Jsf-message-tag

提供:Dev Guides
移動先:案内検索

JSF-h:message

h:messageタグは、UI要素に対応するメッセージを表示します。

JSFタグ

<h:inputText  id = "username"  size = "20" label = "UserName" required = "true">
   <f:validateLength for = "username" minimum = "5" maximum = "20"/>
</h:inputText>
<h:message for = "username" style = "color:red"/>

レンダリングされた出力

入力したユーザー名が20文字を超える場合。

<span style = "color:red">UserName: Validation Error:
   Length is greater than allowable maximum of '20'</span>

入力したユーザー名が5文字未満の場合。

<span style = "color:red">UserName: Validation Error:
   Length is less than allowable minimum of '5'</span>

ユーザー名が入力されていない場合。

<span style = "color:red">UserName: Validation Error:
   Value is required</span>

タグ属性

S.No Attribute & Description
1

id

コンポーネントの識別子

2

binding

バッキングBeanで使用できるコンポーネントへの参照

3

rendered

ブール値。 falseはレンダリングを抑制します

4

styleClass

カスケードスタイルシート(CSS)クラス名

5

for

メッセージが表示されるコンポーネントのID。h:messageにのみ適用可能

6

errorClass

エラーメッセージに適用されるCSSクラス

7

errorStyle

エラーメッセージに適用されるCSSスタイル

8

fatalClass

致命的なメッセージに適用されるCSSクラス

9

fatalStyle

致命的なメッセージに適用されるCSSスタイル

10

globalOnly

h:messagesにのみ適用可能なグローバルメッセージのみを表示する指示。 デフォルト:false

11

infoClass

情報メッセージに適用されるCSSクラス

12

infoStyle

情報メッセージに適用されるCSSスタイル

13

layout

メッセージレイアウトの仕様:テーブルまたはリスト、h:messagesにのみ適用可能

14

showDetail

メッセージの詳細を表示するかどうかを決定するブール値。 h:messagesのデフォルトはfalse、h:messageのデフォルトはtrue

15

showSummary

メッセージの概要を表示するかどうかを決定するブール値。 h:messagesのデフォルトはtrue、h:messageのデフォルトはfalse

16

tooltip

メッセージの詳細をツールチップで表示するかどうかを決定するブール値。ツールチップは、showDetailおよびshowSummaryがtrueの場合にのみレンダリングされます

17

warnClass

警告メッセージのCSSクラス

18

warnStyle

警告メッセージのCSSスタイル

19

style

インラインスタイル情報

20

title

アクセシビリティのために使用される、要素を説明するタイトル。 視覚的なブラウザは通常、タイトルの価値に関するツールチップを作成します

応用例

上記のタグをテストするテストJSFアプリケーションを作成しましょう。

Step Description
1 Create a project with a name helloworld under a package com.finddevguides.test as explained in the JSF - First Application chapter.
2 Modify home.xhtml as explained below. Keep rest of the files unchanged.
3 Compile and run the application to make sure business logic is working as per the requirements.
4 Finally, build the application in the form of war file and deploy it in Apache Tomcat Webserver.
5 Launch your web application using appropriate URL as explained below in the last step.

home.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns = "http://www.w3.org/1999/xhtml">
   <head>
      <title>JSF Tutorial!</title>
   </head>

   <body>
      <h2>h:messages example</h2>
      <hr/>

      <h:form>
         <h:panelGrid id = "panel" columns = "3" border = "0" cellpadding = "10"
               cellspacing = "1">
            <h:outputLabel value = "Enter Username"/>

            <h:inputText  id = "username"  size = "20" label = "UserName"
               required = "true">
               <f:validateLength for = "username" minimum = "5" maximum = "20"/>
            </h:inputText>
            <h:message for = "username" style = "color:red"/>
            <h:outputLabel value = "Enter Password"/>

            <h:inputSecret id = "password" size = "20" label = "Password"
               required = "true" redisplay = "true" >
               <f:validateLength for = "password" minimum = "5" maximum = "10"/>
            </h:inputSecret>
            <h:message for = "password" style = "color:red"/>
            <h:commandButton id = "submit" value = "Submit" action = "result"/>
         </h:panelGrid>
      </h:form>

   </body>
</html>

すべての変更を完了したら、JSF-最初のアプリケーションの章で行ったようにアプリケーションをコンパイルして実行します。 すべてがアプリケーションで問題ない場合、次の結果が生成されます。

JSF h:message