Download FAQ History |  | API Search Feedback

> ## JavaServer Faces Technology

> JavaServer Faces Technology is a user interface framework for building Web applications. The main components of JavaServer Faces technology are:

> - A graphical user interface (GUI) component framework
> - A flexible model for rendering components in different kinds of HTML, or different markup languages and technologies. A `Renderer` generates the markup to render the component and converts the data stored in a model object to types that can be represented in a View.
> - A standard `RenderKit` for generating HTML/4.01 markup.

> In support of the GUI components are the following features:

> - Managed model object creation
> - Input validation
> - Event handling
> - Data conversion between model objects and components
> - Page navigation configuration

> All of this functionality is available via standard Java APIs and XML-based configuration files, and is thus available to applications that aren't based on JSP technology. For the JavaServer Faces applications that do employ JSP technology, the following support is included in JavaServer Faces technology:

> - A standard JSP tag library for generic functions that are independent of the specific `RenderKit` in use (such as adding a validator to a component).
> - A standard JSP tag library for the HTML `RenderKit`, with a tag for each combination of a component type and a method of rendering that component type. Consider the `UISelectOne` component, which represents a list of options, and allows only a single option from the list to be selected. Such a component can be rendered in three different ways (in the basic HTML `RenderKit`), each with a different `Renderer` and a corresponding custom tag:
> - `h:selectone_listbox`--Display a list of all the possible options.
> - `h:selectone_menu`--Display as a combo box (the traditional HTML `select` element with `size="1"`).
> - `h:selectone_radio`--Display as a set of radio buttons and corresponding labels.

> You can also create more complex components like grids, tree controls, and the like. One way to accomplish this is by nesting JavaServer Faces component tags inside each other, just like you nest HTML `input` elements inside a `form` element. You can also define complex components using the JavaServer Faces API.

> The GUI components and well-defined programming model significantly ease the burden of building and maintaining Web applications with server-side GUIs. With minimal effort, you can:

> - Construct a GUI with reusable and extensible components
> - Map GUI components on a page to server-side data
> - Wire client-generated events to server-side application code
> - Save and restore GUI state beyond the life of server requests

> The following code examples contain the JSP page and JavaServer Faces configuration file for the JavaServer Faces version of the example discussed in previous sections:

>     //greeting.jsp

>     <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
>     <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
>     <html>
>     <head><title>Hello</title></head>
>     <body bgcolor="white">
>     <f:use_faces>
>       <h2>My name is Duke.  What is yours?</h2>
>       <h:graphic_image id="wave_img" url="/duke.waving.gif" />
>       <h:form id="helloForm" formName="helloForm" >
>         <h:input_text id="username"
>           columns="25" valueRef="userNameBean.name">
>           <f:validate_required />
>         </h:input_text>
>         <p></p>
>         <h:command_button id="submit" label="Submit"
>           action="success" commandName="submit" />
>         <h:command_button id="reset" label="Reset"
>           action="success" commandName="reset" />
>       </h:form>
>     </f:use_faces>
>     </body>
>     </html>

> Notice how JavaServer Faces custom tags have replaced HTML elements. The user name set as a request parameter is handled by the `h:input` text tag in a model object `UserNameBean` which can be accessed by the response page. The JavaServer Faces tag `f:validate_required` nested inside the `h:input` tag causes a standard validator to be invoked which checks that the user name was entered. The Submit and Reset buttons are linked to commands with `h:command_button` tags.

>     // faces-config.xml
>     ...
>     <navigation-rule>
>       <from-tree-id>/greeting.jsp</from-tree-id>
>       <navigation-case>
>         <from-outcome>success</from-outcome>
>         <to-tree-id>/response.jsp</to-tree-id>
>       </navigation-case>
>     </navigation-rule>
>     <managed-bean>
>       <managed-bean-name>userNameBean</managed-bean-name>
>       <managed-bean-class>hello.UserNameBean</managed-bean-class>
>       <managed-bean-scope>request</managed-bean-scope>
>     </managed-bean>
>     ...

> The JavaServer Faces configuration file specifies when the application should navigate from the greeting to the response page and creates a bean that contains the user name and stores it in the request scope.

Download FAQ History |  | API Search Feedback

All of the material in The Java(TM) Web Services Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.