Standard JSF Tags
- An Overview of the JSF Core Tags
- An Overview of the JSF HTML Tags
- Panels
- The Head, Body, and Form Tags
- Text Fields and Text Areas
- Buttons and Links
- Selection Tags
- Messages
- Conclusion
Development of compelling JSF applications requires a good grasp of the JSF tag libraries. JSF 1.2 had two tag libraries: core and HTML. As of JSF 2.0, there are six libraries with over 100 tags—see Table 4–1. In this chapter, we cover the core library and most of the HTML library. One HTML library component—the data table—is so complex that it is covered separately in Chapter 6.
Table 4–1. JSF Tag Libraries
Library |
Namespace Identifier |
Commonly Used Prefix |
Number of Tags |
See Chapter |
Core |
f: |
27 |
See Table 4–2 |
|
HTML |
h: |
31 |
4 and 6 |
|
Facelets |
ui: |
11 |
5 |
|
Composite Components |
composite: |
12 |
9 |
|
JSTL Core |
c: |
7 |
13 |
|
JSTL Functions |
fn: |
16 |
2 |
An Overview of the JSF Core Tags
The core library contains the tags that are independent of HTML rendering. The core tags are listed in Table 4–2.
Table 4–2. JSF Core Tags
Tag |
Description |
See Chapter |
attribute |
Sets an attribute (key/value) in its parent component. |
4 |
param |
Adds a parameter child component to its parent component. |
4 |
facet |
Adds a facet to a component. |
4 |
actionListener |
Adds an action listener to a component. |
8 |
setPropertyActionListener |
Adds an action listener that sets a property. |
8 |
valueChangeListener |
Adds a value change listener to a component. |
8 |
phaseListener |
Adds a phase listener to the parent view. |
8 |
event |
Adds a component system event listener. |
8 |
converter |
Adds an arbitrary converter to a component. |
7 |
convertDateTime |
Adds a datetime converter to a component. |
7 |
convertNumber |
Adds a number converter to a component. |
7 |
validator |
Adds a validator to a component. |
7 |
validateDoubleRange |
Validates a double range for a component's value. |
7 |
validateLength |
Validates the length of a component's value. |
7 |
validateLongRange |
Validates a long range for a component's value. |
7 |
validateRequired |
Checks that a value is present. |
7 |
validateRegex |
Validates a value against a regular expression. |
7 |
validateBean |
Uses the Bean Validation API (JSR 303) for validation. |
7 |
loadBundle |
Loads a resource bundle, stores properties as a Map. |
2 |
selectitems |
Specifies items for a select one or select many component. |
4 |
selectitem |
Specifies an item for a select one or select many component. |
4 |
verbatim |
Turns text containing markup into a component. |
4 |
viewParam |
Defines a "view parameter" that can be initialized with a request parameter. |
3 |
metadata |
Holds view parameters. May hold other metadata in the future. |
3 |
ajax |
Enables Ajax behavior for components. |
11 |
view |
Use for specifying the page locale or a phase listener. |
2 and 7 |
subview |
Not needed with facelets. |
Most of the core tags represent objects you add to components, such as the following:
- Attributes
- Parameters
- Facets
- Listeners
- Converters
- Validators
- Selection items
All of the core tags are discussed at length in different places in this book, as shown in Table 4–1.
Attributes, Parameters, and Facets
The f:attribute, f:param, and f:facet tags are general-purpose tags to add information to a component. Any component can store arbitrary name/value pairs in its attribute map. You can set an attribute in a page and later retrieve it programatically. For example, in "Supplying Attributes to Converters" on page 289 of Chapter 7, we set the separator character for credit card digit groups like this:
<h:outputText value="#{payment.card}"> <f:attribute name="separator" value="-" /> </h:outputText>
The converter that formats the output retrieves the attribute from the component.
The f:param tag also lets you define a name/value pair, but the value is placed in a separate child component, a much bulkier storage mechanism. However, the child components form a list, not a map. You use f:param if you need to supply a number of values with the same name (or no name at all). You saw an example in "Messages with Variable Parts" on page 42 of Chapter 2, where the h:outputFormat component contains a list of f:param children.
Finally, f:facet adds a named component to a component's facet map. A facet is not a child component; each component has both a list of child components and a map of named facet components. The facet components are usually rendered in a special place. The root of a Facelets page has two facets named "head" and "body". You will see in "Headers, Footers, and Captions" on page 212 of Chapter 6 how to use facets named "header" and "footer" in data tables.
Table 4–3 shows the attributes for the f:attribute, f:param, and f:facet tags.
Table 4–3. Attributes for f:attribute, f:param, and f:facet
Attribute |
Description |
name |
The attribute, parameter component, or facet name |
value |
The attribute or parameter component value (does not apply to f:facet) |
binding, id |
See Table 4–5 on page 107 (f:param only) |