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 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 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 | Referencing a Backing Bean MethodA component tag has a set of attributes for referencing backing bean methodsthat can perform certain functions for the component associated with the tag. Theseattributes are summarized inTable 11-10. Table 11-10 Component Tag Attributes That Reference Backing Bean Methods
Only components that implementActionSource can use theaction andactionListener attributes. Only componentsthat implementEditableValueHolder can use thevalidator orvalueChangeListener attributes. The component tag refers to a backing bean method using a method expressionas a value of one of the attributes. The method referenced by anattribute must follow a particular signature, which is defined by the tag attribute’sdefinition in the TLD. For example, the definition of thevalidator attribute of theinputText tag inhtml_basic.tld is the following: void validate(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.Object) The following four sections give examples of how to use the fourdifferent attributes. Referencing a Method That Performs NavigationIf your page includes a component (such as a button or hyperlink) thatcauses the application to navigate to another page when the component is activated,the tag corresponding to this component must include anaction attribute. This attribute doesone of the following
Thebookcashier.jsp page of the Duke’s Bookstore application has acommandButton tag thatrefers to a backing bean method that calculates the shipping date. If thecustomer has ordered more than $100 (or 100 euros) worth of books, thismethod also sets therendered properties of some of the components totrue and returnsnull; otherwise it returnsreceipt, which causes thebookreceipt.jsp page todisplay. Here is thecommandButton tag from thebookcashier.jsp page: <h:commandButton value="#{bundle.Submit}" action="#{cashier.submit}" />Theaction attribute uses a method expression to refer to thesubmit methodofCashierBean. This method will process the event fired by the component correspondingto this tag. Writing a Method to Handle Navigation describes how to implement thesubmit method ofCashierBean. The application architect must configure a navigation rule that determines which page toaccess given the current page and the logical outcome, which is either returnedfrom the backing bean method or specified in the tag. SeeConfiguring Navigation Rules forinformation on how to define navigation rules in the application configuration resource file. Referencing a Method That Handles an Action EventIf a component on your page generates an action event, and if thatevent is handled by a backing bean method, you refer to the methodby using the component’sactionListener attribute. Thechooselocale.jsp page of the Duke’s Bookstore application includes some components that generateaction events. One of them is theNAmerica component: <h:commandLink action="bookstore" actionListener="#{localeBean.chooseLocaleFromLink}">TheactionListener attribute of this component tag references thechooseLocaleFromLink method using amethod expression. ThechooseLocaleFromLink method handles the event of a user clicking on thehyperlink rendered by this component. Writing a Method to Handle an Action Event describes how to implement a method that handles an action event. Referencing a Method That Performs ValidationIf the input of one of the components on your page is validatedby a backing bean method, you refer to the method from the component’stag using thevalidator attribute. The Coffee Break application includes a method that performs validation of theemailinput component on thecheckoutForm.jsp page. Here is the tag corresponding tothis component: <h:inputText value="#{checkoutFormBean.email}" size="25" maxlength="125" validator="#{checkoutFormBean.validateEmail}"/>This tag references thevalidate method described inWriting a Method to Perform Validation using a method expression. Referencing a Method That Handles a Value-change EventIf you want a component on your page to generate a value-change eventand you want that event to be handled by a backing beanmethod, you refer to the method using the component’svalueChangeListener attribute. Thename component on thebookcashier.jsp page of the Duke’s Bookstore application referencesaValueChangeListener implementation that handles the event of a user entering aname in thename input field: <h:inputText size="50" value="#{cashier.name}" required="true"> <f:valueChangeListener type="listeners.NameChanged" /></h:inputText>For illustration,Writing a Method to Handle a Value-Change Event describes how to implement this listener with a backing beanmethod instead of a listener implementation class. To refer to this backing beanmethod, the tag uses thevalueChangeListener attribute: <h:inputText size="50" value="#{cashier.name}" required="true" valueChangeListener="#{cashier.processValueChange}" /></h:inputText>ThevalueChangeListener attribute of this component tag references theprocessValueChange method ofCashierBeanusing a method expression. TheprocessValueChange method handles the event of a userentering his 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 aValueChangeEvent. Copyright © 2010, Oracle and/or its affiliates. All rights reserved.Legal Notices |