Java EE 6 Pocket Guide by Arun Gupta

Java EE 6 Pocket Guide by Arun Gupta

Author:Arun Gupta [Arun Gupta]
Language: eng
Format: epub, pdf
Tags: COMPUTERS / Programming Languages / Java
ISBN: 9781449336677
Publisher: O'Reilly Media
Published: 2012-09-09T16:00:00+00:00


Composite Components

Using features of Facelets and Resource Handling, JSF defines a composite component as a component that consists of one or more JSF components defined in a Facelets markup file. This .xhtml file resides inside of a resource library. This allows you to create a reusable component from an arbitrary region of a page.

The composite component is defined in the defining page and used in the using page. The defining page defines the metadata (or parameters) using <cc:interface> and the implementation using <cc:implementation>, where cc is the prefix for the http://java.sun.com/jsf/composite/ namespace. Future versions of the JSF specification may relax the requirement to specify metadata, as it can be derived from the implementation itself.

A composite component can be defined using JSF 1.2 as well, but it requires a much deeper understanding of the JSF lifecycle and also authoring multiple files. JSF2 really simplifies the authoring of composite components using just an XHTML file.

Let’s say a Facelet has the following code fragment to display a login form:

<h:form> <h:panelGrid columns="3"> <h:outputText value="Name:" /> <h:inputText value="#{user.name}" id="name"/> <h:message for="name" style="color: red" /> <h:outputText value="Password:" /> <h:inputText value="#{user.password}" id="password"/> <h:message for="password" style="color: red" /> </h:panelGrid> <h:commandButton actionListener= "#{userService.register}" id="loginButton" action="status" value="submit"/> </h:form>

This code renders a table with two rows and three columns, as shown in Figure 7-1.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.