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 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 | Setting Up a PageA typical JavaServer Faces page includes the following elements:
This section tells you how to add these elements to your pagesand briefly describes thesubview tag for including JavaServer Faces pages inside other pages. To use the JavaServer Faces UI components in your JSP page, you needto give the page access to the two standard tag libraries: theJavaServer Faces HTML render kit tag library and the JavaServer Faces core taglibrary. The JavaServer Faces standard HTML render kit tag library defines tags that representcommon HTML user interface components. The JavaServer Faces core tag library defines tagsthat perform core actions and are independent of a particular render kit. Using these tag libraries is similar to using any other custom taglibrary. This chapter assumes that you are familiar with the basics of usingcustom tags in JSP pages (seeUsing Custom Tags). As is the case with any tag library, each JavaServer Faces tag librarymust have a TLD that describes it. Thehtml_basic TLD describes the JavaServerFaces standard HTML render kit tag library. Thejsf_core TLD describes theJavaServer Faces core tag library. Refer to theTLD documentation athttp://download.oracle.com/javaee/5/javaserverfaces/1.2/docs/tlddocs/ for a complete list of theJavaServer Faces tags and their attributes. To use any of the JavaServer Faces tags, you need to include thesetaglib directives at the top of each page containing the tags defined bythese tag libraries: <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %><%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> Theuri attribute value uniquely identifies the TLD. Theprefix attribute value isused to distinguish tags belonging to the tag library. You can use otherprefixes rather than theh orf prefixes. However, you must usethe prefix you have chosen when including the tag in the page. Forexample, theform tag must be referenced in the page using theh prefix because the preceding tag library directive uses theh prefix to distinguishthe tags defined inhtml_basic.tld: <h:form ...> A page containing JavaServer Faces tags is represented by a tree of components.At the root of the tree is theUIViewRoot component. Theview tagrepresents this component on the page. Therefore, all component tags on the pagemust be enclosed in theview tag, which is defined in thejsf_coreTLD: <f:view> ... other JavaServer Faces tags, possibly mixed with other content ...</f:view> You can enclose other content, including HTML and other JSP tags, within theview tag, but all JavaServer Faces tags must be enclosed within theviewtag. Theview tag has four optional attributes:
An advanced developer might implement the methods referenced bybeforePhase andafterPhaseto perform such functions as initialize or release resources on a per-page basis.This feature is outside of the scope of this tutorial. Theform tag is nested inside of theview tag. As its namesuggests, theform tag represents a form, which is submitted when a buttonor hyperlink on the page is clicked. For the data of other componentson the page to be submitted with the form, the tags representing thecomponents must be nested inside theform tag. SeeAdding a Form Component for moredetails on using theform tag. If you want to include a page containing JavaServer Faces tags within anotherJSP page that includes JavaServer Faces tags, you must enclose the entire nestedpage in asubview tag. You can add thesubview tag on theparent page and nest ajsp:include inside it to include the page: <f:subview> <jsp:include page="theNestedPage.jsp" /></f:subview> You can also include thesubview tag inside the nested page, but itmust enclose all the JavaServer Faces tags on the nested page. Thesubview tag has two optional attributes:binding andrendered. Thebindingattribute binds to a component that implementsNamingContainer. One potential use case of bindinga subview component to a bean is if you want to dynamically addcomponents to the subview in the backing bean. Therendered attribute can be set totrue orfalse, indicating whetheror not the components nested in thesubview tag should be rendered. In summary, a typical JSP page that uses JavaServer Faces tags will looksomewhat like this: <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %><%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %><f:view> <h:form> other JavaServer Faces tags and core tags, including one or more button or hyperlink components for submitting the form </h:form></f:view> The sectionsUsing the Core Tags andAdding UI Components to a Page Using the HTML Component Tags describe how to use the core tagsfrom the JavaServer Faces core tag library and the component tags from theJavaServer Faces standard HTML render kit tag library. Copyright © 2010, Oracle and/or its affiliates. All rights reserved.Legal Notices |