Binding Converters, Listeners, and Validators to Backing Bean Properties (original) (raw)
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
The style and styleClass Attributes
The value and binding Attributes
Rendering a Text Field with the inputText Tag
Rendering a Label with the outputLabel Tag
Rendering a Hyperlink with the outputLink Tag
Displaying a Formatted Message with the outputFormat Tag
Rendering a Password Field with the inputSecret Tag
Using Command Components for Performing Actions and Navigation
Rendering a Button with the commandButton Tag
Rendering a Hyperlink with the commandLink Tag
Using Data-Bound Table Components
Adding Graphics and Images with the graphicImage Tag
Laying Out Components with the UIPanel Component
Rendering Components for Selecting One Value
Displaying a Check Box Using the selectBooleanCheckbox Tag
Displaying a Menu Using the selectOneMenu Tag
Rendering Components for Selecting Multiple Values
The UISelectItem, UISelectItems, and UISelectItemGroup Components
Displaying Error Messages with the message and messages 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
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
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
37. The Duke's Bank Application
Binding Converters, Listeners, and Validators to Backing Bean Properties
As described previously in this chapter, a page author can bind converter, listener, and validator implementations to backing bean properties using the binding attributes of the tags used to register the implementations on components.
This technique has similar advantages to binding component instances to backing bean properties, as described in Binding Component Values and Instances to External Data Sources. In particular, binding a converter, listener, or validator implementation to a backing bean property yields the following benefits:
- The backing bean can instantiate the implementation instead of allowing the page author to do so.
- The backing bean can programmatically modify the attributes of the implementation. In the case of a custom implementation, the only other way to modify the attributes outside of the implementation class would be to create a custom tag for it and require the page author to set the attribute values from the page.
Whether you are binding a converter, listener, or validator to a backing bean property, the process is the same for any of the implementations:
- Nest the converter, listener, or validator tag within an appropriate component tag.
- Make sure that the backing bean has a property that accepts and returns the converter, listener, or validator implementation class that you want to bind to the property.
- Reference the backing bean property using a value expression from the binding attribute of the converter, listener, or validator tag.
For example, say that you want to bind the standard DateTime converter to a backing bean property because the application developer wants the backing bean to set the formatting pattern of the user’s input rather than let the page author do it. First, the page author registers the converter onto the component by nesting the convertDateTime tag within the component tag. Then, the page author references the property with the binding attribute of the convertDateTime tag:
<h:inputText value="#{LoginBean.birthDate}"> <f:convertDateTime binding="#{LoginBean.convertDate}" />
The convertDate property would look something like this:
private DateTimeConverter convertDate; public DateTimeConverter getConvertDate() { ... return convertDate; { public void setConvertDate(DateTimeConverter convertDate) { convertDate.setPattern("EEEEEEEE, MMM dd, yyyy"); this.convertDate = convertDate; }
See Writing Properties Bound to Converters, Listeners, or Validators for more information on writing backing bean properties for converter, listener, and validator implementations.
Copyright © 2010, Oracle and/or its affiliates. All rights reserved. Legal Notices