2. Using the Tutorial Examples
3. Getting Started with Web Applications
4. JavaServer Faces Technology
7. Using JavaServer Faces Technology in Web Pages
8. Using Converters, Listeners, and Validators
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
9. Developing with JavaServer Faces Technology
10. JavaServer Faces Technology: Advanced Concepts
11. Using Ajax with JavaServer Faces Technology
12. Composite Components: Advanced Topics and Example
13. Creating Custom UI Components and Other Custom Objects
14. Configuring JavaServer Faces Applications
16. Uploading Files with Java Servlet Technology
17. Internationalizing and Localizing Web Applications
18. Introduction to Web Services
19. Building Web Services with JAX-WS
20. Building RESTful Web Services with JAX-RS
21. JAX-RS: Advanced Topics and Example
23. Getting Started with Enterprise Beans
24. Running the Enterprise Bean Examples
25. A Message-Driven Bean Example
26. Using the Embedded Enterprise Bean Container
27. Using Asynchronous Method Invocation in Session Beans
Part V Contexts and Dependency Injection for the Java EE Platform
28. Introduction to Contexts and Dependency Injection for the Java EE Platform
29. Running the Basic Contexts and Dependency Injection Examples
30. Contexts and Dependency Injection for the Java EE Platform: Advanced Topics
31. Running the Advanced Contexts and Dependency Injection Examples
32. Introduction to the Java Persistence API
33. Running the Persistence Examples
34. The Java Persistence Query Language
35. Using the Criteria API to Create Queries
36. Creating and Using String-Based Criteria Queries
37. Controlling Concurrent Access to Entity Data with Locking
38. Using a Second-Level Cache with Java Persistence API Applications
39. Introduction to Security in the Java EE Platform
40. Getting Started Securing Web Applications
41. Getting Started Securing Enterprise Applications
42. Java EE Security: Advanced Topics
Part VIII Java EE Supporting Technologies
43. Introduction to Java EE Supporting Technologies
45. Resources and Resource Adapters
46. The Resource Adapter Example
47. Java Message Service Concepts
48. Java Message Service Examples
49. Bean Validation: Advanced Topics
50. Using Java EE Interceptors
51. Duke's Bookstore Case Study Example
52. Duke's Tutoring Case Study Example
53. Duke's Forest Case Study Example
A component tag has a set of attributes for referencing managed bean methods that can perform certain functions for the component associated with the tag. These attributes are summarized in Table 8-5.
Table 8-5 Component Tag Attributes That Reference Managed Bean Methods
Attribute
Function
Refers to a managed bean method that performs navigation processing for the component and returns a logical outcome String
Refers to a managed bean method that handles action events
Refers to a managed bean method that performs validation on the component’s value
Refers to a managed bean method that handles value-change events
Only components that implement javax.faces.component.ActionSource can use the action and actionListener attributes. Only components that implement javax.faces.component.EditableValueHolder can use the validator or valueChangeListener attributes.
The component tag refers to a managed bean method using a method expression as a value of one of the attributes. The method referenced by an attribute must follow a particular signature, which is defined by the tag attribute’s definition in the documentation at http://docs.oracle.com/javaee/6/javaserverfaces/2.1/docs/vdldocs/facelets/. For example, the definition of the validator attribute of the inputText tag is the following:
void validate(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.Object)
The following sections give examples of how to use the attributes.
Referencing a Method That Performs NavigationIf your page includes a component, such as a button or a hyperlink, that causes the application to navigate to another page when the component is activated, the tag corresponding to this component must include an action attribute. This attribute does one of the following:
Specifies a logical outcome String that tells the application which page to access next
References a managed bean method that performs some processing and returns a logical outcome String
The following example shows how to reference a navigation method:
<h:commandButton value="#{bundle.Submit}" action="#{cashier.submit}" />
See Writing a Method to Handle Navigation for information on how to write such a method.
Referencing a Method That Handles an Action EventIf a component on your page generates an action event, and if that event is handled by a managed bean method, you refer to the method by using the component’s actionListener attribute.
The following example shows how such a method could be referenced:
<h:commandLink id="Duke" action="bookstore" actionListener="#{actionBean.chooseBookFromLink}">
The actionListener attribute of this component tag references the chooseBookFromLink method using a method expression. The chooseBookFromLink method handles the event when the user clicks the hyperlink rendered by this component. See Writing a Method to Handle an Action Event for information on how to write such a method.
Referencing a Method That Performs ValidationIf the input of one of the components on your page is validated by a managed bean method, refer to the method from the component’s tag by using the validator attribute.
The following example from The guessnumber CDI Example shows how to reference a method that performs validation on inputGuess, an input component:
<h:inputText id="inputGuess" value="#{userNumberBean.userNumber}" required="true" size="3" disabled="#{userNumberBean.number eq userNumberBean.userNumber}" validator="#{userNumberBean.validateNumberRange}"> </h:inputText>
The managed bean method validateNumberRange verifies that the input value is within the valid range, which changes each time another guess is made. See Writing a Method to Perform Validation for information on how to write such a method.
Referencing a Method That Handles a Value-Change EventIf you want a component on your page to generate a value-change event and you want that event to be handled by a managed bean method instead of a javax.faces.event.ValueChangeListener implementation, you refer to the method by using the component’s valueChangeListener attribute:
<h:inputText id="name" size="30" value="#{cashier.name}" required="true" valueChangeListener="#{cashier.processValueChange}" /> </h:inputText>
The valueChangeListener attribute of this component tag references the processValueChange method of CashierBean by using a method expression. The processValueChange method handles the event of a user entering a name in the input field rendered by this component.
Writing a Method to Handle a Value-Change Event describes how to implement a method that handles a javax.faces.event.ValueChangeEvent.
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Legal Notices
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4