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 Referencing Localized Static Data Converting a Component's Value Registering Listeners on Components Registering a Value-Change Listener on a Component Registering an Action Listener on a Component 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 the Standard ValidatorsJavaServer Faces technology provides a set of standard classes and associated tags thatpage authors and application developers can use to validate a component’s data.Table 11-7lists all the standard validator classes and the tags that allow you touse the validators from the page. Table 11-7 The Validator Classes
All these validator classes implement theValidator interface. Component writers and application developerscan also implement this interface to define their own set of constraints fora component’s value. Similarly to the standard converters, each of these validators has one or morestandard error messages associated with it. If you have registered one of thesevalidators onto a component on your page, and the validator is not ableto validate the component’s value, the validator’s error message will display on thepage. For example, the error message that displays when the component’s value exceedsthe maximum value allowed byLongRangeValidator is the following: {1}: Validation Error: Value is greater than allowable maximum of "{0}"In this case the{1} substitution parameter is replaced by the component’s labelor ID, and the{0} substitution parameter is replaced with the maximum valueallowed by the validator. See section 2.5.4 of the JavaServer Faces specification for the complete list oferror messages. SeeDisplaying Error Messages with themessage andmessages Tags for information on how to display validation error messageson the page when validation fails. Validating a Component’s ValueIn order to validate a component’s value using a particular validator, you needto register the validator on the component. You have three ways to dothis:
SeeReferencing a Method That Performs ValidationReferencing a Method That Performs Validation for more information on using thevalidator attribute. ThevalidatorId attribute works similarly to theconverterId attribute of theconvertertag, as described inConverting a Component's Value. SeeBinding Converters, Listeners, and Validators to Backing Bean Properties for more information on using thebindingattribute of thevalidator tag. Keep in mind that validation can be performed only on components that implementEditableValueHolder because these components accept values that can be validated. Using theLongRangeValidatorThe Duke’s Bookstore application uses avalidateLongRange tag on thequantity input field ofthebookshowcart.jsp page: <h:inputText size="4" value="#{item.quantity}" > <f:validateLongRange minimum="1"/></h:inputText><h:message for="quantity"/>This tag requires that the user enter a number that is atleast 1. Thesize attribute specifies that the number can have nomore than four digits. ThevalidateLongRange tag also has amaximum attribute, with whichyou can set a maximum value of the input. The attributes of all the standard validator tags accept value expressions. This meansthat the attributes can reference backing bean properties rather than specify literal values.For example, thevalidateLongRange tag in the preceding example can reference a backingbean property calledminimum to get the minimum value acceptable to thevalidator implementation: <f:validateLongRange minimum="#{ShowCartBean.minimum}" />Copyright © 2010, Oracle and/or its affiliates. All rights reserved.Legal Notices |