Showing posts with label Facelets. Show all posts
Showing posts with label Facelets. Show all posts

Wednesday, October 26, 2011

Setting Up a JSF web page -- Java EE 6 Tutorial

From the Java EE 6 Tutorial here.


A typical JavaServer Faces web page includes the following elements:

  • A set of namespace declarations that declare the JavaServer Faces tag libraries

  • Optionally, the new HTML head (h:head) and body (h:body) tags

  • A form tag (h:form) that represents the user input components


To add the JavaServer Faces components to your web page, you need to provide the page access to the two standard tag libraries: the JavaServer Faces HTML tag library and the JavaServer Faces core tag library. The JavaServer Faces standard HTML tag library defines tags that represent common HTML user interface components. This library is linked to the HTML render kit at http://download.oracle.com/javaee/6/javaserverfaces/2.1/docs/renderkitdocs/. The JavaServer Faces core tag library defines tags that perform core actions.

For a complete list of JavaServer Faces Facelets tags and their attributes, refer to the documentation at http://download.oracle.com/javaee/6/javaserverfaces/2.1/docs/vdldocs/facelets/.

To use any of the JavaServer Faces tags, you need to include appropriate directives at the top of each page specifying the tag libraries.

For Facelets applications, the XML namespace directives uniquely identify the tag library URI and the tag prefix.

For example, when creating a Facelets XHTML page, include namespace directives as follows:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">

The XML namespace URI identifies the tag library location, and the prefix value is used to distinguish the tags belonging to that specific tag library. You can also use other prefixes instead of the standard h or f. However, when including the tag in the page, you must use the prefix that you have chosen for the tag library. For example, in the following web page, the form tag must be referenced using the h prefix because the preceding tag library directive uses the h prefix to distinguish the tags defined in HTML tag library:
<h:form ...>

The sections Adding Components to a Page Using HTML Tags and Using Core Tags describe how to use the component tags from the JavaServer Faces standard HTML tag library and the core tags from the JavaServer Faces core tag library.

Composite Components -- The Java EE 6 Tutorial -- JSF 2.0

From Java EE 6 Tutorial here.


JavaServer Faces technology offers the concept of composite components with Facelets. A composite component is a special type of template that acts as a component.

Any component is essentially a piece of reusable code that behaves in a particular way. For example, an inputText component accepts user input. A component can also have validators, converters, and listeners attached to it to perform certain defined actions.

A composite component consists of a collection of markup tags and other existing components. This reusable, user-created component has a customized, defined functionality and can have validators, converters, and listeners attached to it like any other component.

With Facelets, any XHTML page that contains markup tags and other components can be converted into a composite component. Using the resources facility, the composite component can be stored in a library that is available to the application from the defined resources location.

Table 5-3 lists the most commonly used composite tags and their functions.



Table 5-3 Composite Component Tags



































TagFunction
composite:interfaceDeclares the usage contract for a composite component. The composite component can be used as a single component whose feature set is the union of the features declared in the usage contract.
composite:implementationDefines the implementation of the composite component. If a composite:interface element appears, there must be a corresponding composite:implementation.
composite:attributeDeclares an attribute that may be given to an instance of the composite component in which this tag is declared.
composite:insertChildrenAny child components or template text within the composite component tag in the using page will be reparented into the composite component at the point indicated by this tag’s placement within the composite:implementation section.
composite:valueHolderDeclares that the composite component whose contract is declared by the composite:interface in which this element is nested exposes an implementation of ValueHolder suitable for use as the target of attached objects in the using page.
composite:editableValueHolderDeclares that the composite component whose contract is declared by the composite:interface in which this element is nested exposes an implementation of EditableValueHolder suitable for use as the target of attached objects in the using page.
composite:actionSourceDeclares that the composite component whose contract is declared by the composite:interface in which this element is nested exposes an implementation of ActionSource2 suitable for use as the target of attached objects in the using page.

For more information and a complete list of Facelets composite tags, see the documentation at http://download.oracle.com/javaee/6/javaserverfaces/2.1/docs/vdldocs/facelets/.

Java Tutorial Highlights - JSF Templating

From the Java Tutorial here.

JavaServer Faces technology provides the tools to implement user interfaces that are easy to extend and reuse. Templating is a useful Facelets feature that allows you to create a page that will act as the base, or template, for the other pages in an application. By using templates, you can reuse code and avoid recreating similarly constructed pages. Templating also helps in maintaining a standard look and feel in an application with a large number of pages.

Table 5-2 lists Facelets tags that are used for templating and their respective functionality.



Table 5-2 Facelets Templating Tags



















































TagFunction
ui:componentDefines a component that is created and added to the component tree.
ui:compositionDefines a page composition that optionally uses a template. Content outside of this tag is ignored.
ui:debugDefines a debug component that is created and added to the component tree.
ui:decorateSimilar to the composition tag but does not disregard content outside this tag.
ui:defineDefines content that is inserted into a page by a template.
ui:fragmentSimilar to the component tag but does not disregard content outside this tag.
ui:includeEncapsulate and reuse content for multiple pages.
ui:insertInserts content into a template.
ui:paramUsed to pass parameters to an included file.
ui:repeatUsed as an alternative for loop tags, such as c:forEach or h:dataTable.
ui:removeRemoves content from a page.

For more information on Facelets templating tags, see the documentation at http://download.oracle.com/javaee/6/javaserverfaces/2.1/docs/vdldocs/facelets/.

The Facelets tag library includes the main templating tag ui:insert. A template page that is created with this tag allows you to define a default structure for a page. A template page is used as a template for other pages, usually referred to as client pages.

Facelets Tutorial Highlights

Facelets Tutorial Highlights from here.

The term Facelets refers to the view declaration language for JavaServer Faces technology. JavaServer Pages (JSP) technology, previously used as the presentation technology for JavaServer Faces, does not support all the new features available in JavaServer Faces 2.0. JSP technology is considered to be a deprecated presentation technology for JavaServer Faces 2.0. Facelets is a part of the JavaServer Faces specification and also the preferred presentation technology for building JavaServer Faces technology-based applications.

What Is Facelets?




Facelets is a powerful but lightweight page declaration language that is used to build JavaServer Faces views using HTML style templates and to build component trees. Facelets features include the following:

  • Use of XHTML for creating web pages

  • Support for Facelets tag libraries in addition to JavaServer Faces and JSTL tag libraries

  • Support for the Expression Language (EL)

  • Templating for components and pages


JavaServer Faces technology supports various tag libraries to add components to a web page. To support the JavaServer Faces tag library mechanism, Facelets uses XML namespace declarations. Table 5-1 lists the tag libraries supported by Facelets.



Table 5-1 Tag Libraries Supported by Facelets













































Tag LibraryURIPrefixExampleContents
JavaServer Faces Facelets Tag Libraryhttp://java.sun.com/jsf/faceletsui:ui:component

ui:insert
Tags for templating
JavaServer Faces HTML Tag Libraryhttp://java.sun.com/jsf/htmlh:h:head

h:body

h:outputText

h:inputText
JavaServer Faces component tags for all UIComponents
JavaServer Faces Core Tag Libraryhttp://java.sun.com/jsf/coref:f:actionListener

f:attribute
Tags for JavaServer Faces custom actions that are independent of any particular RenderKit
JSTL Core Tag Libraryhttp://java.sun.com/jsp/jstl/corec:c:forEach

c:catch
JSTL 1.1 Core Tags
JSTL Functions Tag Libraryhttp://java.sun.com/jsp/jstl/functionsfn:fn:toUpperCase

fn:toLowerCase
JSTL 1.1 Functions Tags

In addition, Facelets supports tags for composite components for which you can declare custom prefixes. For more information on composite components, see Composite Components.