2. Using the Tutorial Examples 3. Getting Started with Web Applications 5. JavaServer Pages Technology 7. JavaServer Pages Standard Tag Library 10. JavaServer Faces Technology 11. Using JavaServer Faces Technology in JSP Pages The Example JavaServer Faces Application Adding UI Components to a Page Using the HTML Component Tags Thestyle andstyleClass Attributes Thevalue andbinding Attributes Rendering a Text Field with theinputText Tag Rendering a Label with theoutputLabel Tag Rendering a Hyperlink with theoutputLink Tag Displaying a Formatted Message with theoutputFormat Tag Rendering a Password Field with theinputSecret Tag Using Command Components for Performing Actions and Navigation Rendering a Button with thecommandButton Tag Rendering a Hyperlink with thecommandLink Tag Using Data-Bound Table Components Adding Graphics and Images with thegraphicImage Tag Laying Out Components with theUIPanel Component Rendering Components for Selecting One Value Displaying a Check Box Using theselectBooleanCheckbox Tag Displaying a Menu Using theselectOneMenu Tag Rendering Components for Selecting Multiple Values TheUISelectItem,UISelectItems, andUISelectItemGroup Components Displaying Error Messages with themessage andmessages Tags Converting a Component's Value Registering Listeners on Components Registering a Value-Change Listener on a Component Registering an Action Listener on a Component Validating a Component's Value Binding Component Values and Instances to External Data Sources Binding a Component Value to a Property Binding a Component Value to an Implicit Object Binding a Component Instance to a Bean Property Binding Converters, Listeners, and Validators to Backing Bean Properties Referencing a Backing Bean Method Referencing a Method That Performs Navigation Referencing a Method That Handles an Action Event Referencing a Method That Performs Validation Referencing a Method That Handles a Value-change Event 12. Developing with JavaServer Faces Technology 13. Creating Custom UI Components 14. Configuring JavaServer Faces Applications 15. Internationalizing and Localizing Web Applications 16. Building Web Services with JAX-WS 17. Binding between XML Schema and Java Classes 19. SOAP with Attachments API for Java 21. Getting Started with Enterprise Beans 23. A Message-Driven Bean Example 24. Introduction to the Java Persistence API 25. Persistence in the Web Tier 26. Persistence in the EJB Tier 27. The Java Persistence Query Language 28. Introduction to Security in the Java EE Platform 29. Securing Java EE Applications 31. The Java Message Service API 32. Java EE Examples Using the JMS API 36. The Coffee Break Application | Using Localized DataJavaServer Faces applications make use of three different kinds of data that canbe localized:
This section discusses how to access the first two kinds of datafrom the page.Performing Localization explains how to produce localized error messages as well ashow to localize dynamic data. If you are not familiar with the basicsof localizing web applications, seeChapter 15, Internationalizing and Localizing Web Applications. All data in the Duke’s Bookstore application have been localized for Spanish, French,German, and American English. The image map on the first page allows youto select your preferred locale. SeeChapter 13, Creating Custom UI Components for information on how theimage map custom component was created. All the localized data is stored in resource bundles, which are represented aseitherResourceBundle classes or text files, usually with the extension.properties. For moreinformation about resource bundles, seehttp://download.oracle.com/javase/tutorial/i18n/index.html. After the application developer has produced a resource bundle, the application architect putsit in the same directory as the application classes. The static text datafor the Duke’s Bookstore application is stored in aResourceBundle class calledBookstoreMessages. Theerror messages are stored in another resource bundle calledApplicationMessages. After theresource bundles have been created and before their data can be accessed, theymust be made available to the application, as explained in the following section. Loading a Resource BundleTo reference error messages or static data from the page, you first needto make available the resource bundle containing the data. To make available resource bundles that contain static data, you need to doone of two things:
Here is an exampleloadBundle tag frombookstore.jsp: <f:loadBundle var="bundle" basename="messages.BookstoreMessages" /> Thebasename attribute value specifies the fully-qualified class name of theResourceBundle class, whichin this case is located in themessages package of thebookstore application. Thevar attribute is an alias to theResourceBundle class. This alias can beused by other tags in the page in order to access thelocalized messages. In the case of resource bundles that contain error messages, you need toregister the resource bundle with the application in the configuration file using themessage-bundle element, as explained inRegistering Custom Error Messages. One exception is if you are referencingthe error messages from the input component attributes described inReferencing Error Messages. In that case,you load the resource bundles containing these messages in the same way youload resource bundles containing static text. Referencing Localized Static DataTo reference static localized data from a resource bundle, you use a valueexpression from an attribute of the component tag that will display the localizeddata. You can reference the message from any component tag attribute that isenabled to accept value expressions. The value expression has the notationvar.message, in whichvar matches thevarattribute of theloadBundle tag or thevar element in the configuration file, andmessage matches the key of the message contained in the resource bundle, referredto by thevar attribute. Here is an example frombookstore.jsp: <h:outputText value="#{bundle.Talk}"/>Notice thatbundle matches thevar attribute from theloadBundle tag and thatTalk matches the key in theResourceBundle. Another example is thegraphicImage tag fromchooselocale.jsp: <h:graphicImage url="/template/world.jpg" alt="#{bundle.ChooseLocale}" usemap="#worldMap" />Thealt attribute is enabled to accept value expressions. In this case, thealt attribute refers to localized text that will be included in the alternativetext of the image rendered by this tag. SeeCreating Custom Component Classes andEnabling Component Properties to Accept Expressions for information on how to enable value binding onyour custom component’s attributes. Referencing Error MessagesA JavaServer Faces page uses themessage ormessages tags to accesserror messages, as explained inDisplaying Error Messages with themessage andmessages Tags. The error messages that these tags access include:
When a converter or validator is registered on an input component, the appropriateerror message is automatically queued on the component. A page author can override the error messages queued on a component byusing the following attributes of the component’s tag:
All three attributes are enabled to take literal values and value expressions. Ifan attribute uses a value expression, this expression references the error message ina resource bundle. This resource bundle must be made available to the applicationin one of the following ways:
Conversely, themessage-bundle element must be used to make available to the applicationthose resource bundles containing custom error messages that are queued on the componentas a result of a custom converter or validator being registered on thecomponent. Thebookcashier.jsp page includes an example of therequiredMessage attribute using a valueexpression to reference an error message: <h:inputText size="19" required="true" requiredMessage="#{customMessages.ReqMessage}" > ...</h:inputText><h:message styleClass="error-message" for="ccno"/>The value expression thatrequiredMessage is using in this example references the errormessage with theReqMessage key in the resource bundle,customMessages. This message replaces the corresponding message queued on the component and will displaywherever themessage ormessages tag is placed on the page. SeeRegistering Custom Error Messages andRegistering Custom Localized Static Text for information on how to use themessage-bundle andresource-bundle element to register resource bundles that contain error messages. Copyright © 2010, Oracle and/or its affiliates. All rights reserved.Legal Notices |