JBoss.orgCommunity Documentation

Component Reference

A reference guide to the components of the RichFaces 4 (draft) framework

Logo

Abstract

This book details each component in the RichFaces 4 framework, including examples of their use in applications.


1. Introduction
1.1. Libraries
2. Common Ajax attributes
2.1. Rendering
2.1.1. render
2.1.2. ajaxRendered
2.1.3. limitRender
2.2. Queuing and traffic control
2.2.1. queue
2.2.2. requestDelay
2.2.3. ignoreDupResponses
2.3. Data processing
2.3.1. execute
2.3.2. immediate
2.3.3. bypassUpdates
2.4. Action and navigation
2.4.1. action
2.4.2. actionListener
2.5. Events and JavaScript interactions
2.5.1. onsubmit
2.5.2. onbegin
2.5.3. onclick
2.5.4. onsuccess
2.5.5. oncomplete
2.5.6. onerror
2.5.7. data
3. Common features
3.1. Positioning and appearance of components
3.2. Calling available JavaScript methods
I. a4j tag library
4. Actions
4.1. <a4j:ajax>
4.1.1. Reference data
4.2. <a4j:actionParam>
4.2.1. Basic usage
4.2.2. Interoperability
4.2.3. Reference data
4.3. <a4j:commandButton>
4.3.1. Basic usage
4.3.2. Reference data
4.4. <a4j:commandLink>
4.4.1. Basic usage
4.4.2. Reference data
4.5. <rich:componentControl>
4.5.1. Basic usage
4.5.2. Attaching to a component
4.5.3. Parameters and JavaScript
4.5.4. Timing
4.5.5. Reference data
4.6. <a4j:jsFunction>
4.6.1. Basic usage
4.6.2. Parameters and JavaScript
4.6.3. Reference data
4.7. <a4j:poll>
4.7.1. Timing options
4.7.2. Reference data
4.8. <a4j:push>
4.8.1. Timing options
4.8.2. Reference data
5. Resources
5.1. <a4j:keepAlive>
5.1.1. Basic usage
5.1.2. Non-Ajax requests
5.1.3. Reference data
6. Containers
6.1. <a4j:include>
6.1.1. Basic usage
6.1.2. Reference data
6.2. <a4j:outputPanel>
6.2.1. Panel appearance
6.2.2. Reference data
6.3. <a4j:region>
6.3.1. Reference data
7. Validation
7.1. <rich:ajaxValidator>
7.1.1. Custom validators
7.1.2. Reference data
7.2. <rich:beanValidator>
7.2.1. Basic usage
7.2.2. Reference data
7.3. <rich:graphValidator>
7.3.1. Basic usage
7.3.2. Bean values
7.3.3. Reference data
8. Processing management
8.1. <a4j:queue>
8.1.1. Queue size
8.1.2. <a4j:queue> client-side events
8.1.3. Reference data
8.2. <a4j:log>
8.2.1. Log monitoring
8.2.2. Reference data
8.3. <a4j:status>
8.3.1. Customizing the text
8.3.2. Specifying a region
8.3.3. Reference data
II. rich tag library
9. Rich inputs
9.1. <rich:autocomplete>
9.1.1. Basic usage
9.1.2. Interactivity options
9.1.3. Reference data
9.2. <rich:calendar>
9.2.1. Basic usage
9.2.2. Using a data model
9.2.3. Behavior and appearance
9.2.4. Time of day
9.2.5. <rich:calendar> events
9.2.6. Reference data
9.3. <rich:inplaceInput>
9.3.1. Basic usage
9.3.2. Interactivity options
9.3.3. Reference data
9.4. <rich:inplaceSelect>
9.4.1. Basic usage
9.4.2. Interactivity options
9.4.3. <rich:inplaceSelect> events
9.4.4. Reference data
9.5. <rich:inputNumberSlider>
9.5.1. Basic usage
9.5.2. Interactivity options
9.5.3. Reference data
9.6. <rich:inputNumberSpinner>
9.6.1. Basic usage
9.6.2. Interactivity options
9.6.3. Reference data
9.7. <rich:select>
9.7.1. Basic usage
9.7.2. Using <rich:select> as a combo-box
9.7.3. Reference data
10. Panels and containers
10.1. <rich:panel>
10.1.1. Basic usage
10.1.2. Adding a header
10.1.3. Reference data
10.2. <rich:popupPanel>
10.2.1. Basic usage
10.2.2. Showing and hiding the pop-up
10.2.3. Modal and non-modal panels
10.2.4. Size and positioning
10.2.5. Contents of the pop-up
10.2.6. Header and controls
10.2.7. Reference data
10.3. <rich:accordion>
10.3.1. Basic usage
10.3.2. Switching panels
10.3.3. <rich:accordion> client-side events
10.3.4. <rich:accordion> server-side events
10.3.5. Reference data
10.4. <rich:accordionItem>
10.4.1. Basic usage
10.4.2. <rich:accordionItem> client-side events
10.4.3. Reference data
10.5. <rich:collapsiblePanel>
10.5.1. Basic usage
10.5.2. Expanding and collapsing the panel
10.5.3. Appearance
10.5.4. <rich:collapsiblePanel> server-side events
10.5.5. Reference data
10.6. <rich:tab>
10.6.1. Basic usage
10.6.2. Header labeling
10.6.3. Switching tabs
10.6.4. <rich:tab> client-side events
10.6.5. Reference data
10.7. <rich:tabPanel>
10.7.1. Switching panels
10.7.2. <rich:tabPanel> client-side events
10.7.3. <rich:tabPanel> server-side events
10.7.4. Reference data
10.8. <rich:toggleControl>
10.8.1. Basic usage
10.8.2. Specifying the next state
10.8.3. Reference data
10.9. <rich:togglePanel>
10.9.1. Basic usage
10.9.2. Toggling between components
10.9.3. Reference data
10.10. <rich:togglePanelItem>
10.10.1. Reference data
11. Tables and grids
11.1. <a4j:repeat>
11.1.1. Basic usage
11.1.2. Limited views and partial updates
11.1.3. Reference data
11.2. <rich:column>
11.2.1. Basic usage
11.2.2. Spanning columns
11.2.3. Spanning rows
11.2.4. Reference data
11.3. <rich:columnGroup>
11.3.1. Complex headers
11.3.2. Reference data
11.4. <rich:dataGrid>
11.4.1. Basic usage
11.4.2. Customizing the grid
11.4.3. Patial updates
11.4.4. Reference data
11.5. <rich:dataTable>
11.5.1. Basic usage
11.5.2. Customizing the table
11.5.3. Partial updates
11.5.4. Reference data
11.6. <rich:extendedDataTable>
11.6.1. Basic usage
11.6.2. Table appearance
11.6.3. Extended features
11.6.4. Reference data
11.7. <rich:list>
11.7.1. Basic usage
11.7.2. Type of list
11.7.3. Bullet and numeration appearance
11.7.4. Customizing the list
11.7.5. Reference data
11.8. Table filtering
11.9. Table sorting
12. Output and messages
12.1. <rich:progressBar>
12.1.1. Basic usage
12.1.2. Customizing the appearance
12.1.3. Using set intervals
12.1.4. Update mode
12.1.5. Reference data
12.2. <rich:toolTip>
12.2.1. Basic usage
12.2.2. Attaching the tool-tip to another component
12.2.3. Appearance
12.2.4. Update mode
12.2.5. <rich:toolTip> client-side events
12.2.6. Reference data
13. Layout and appearance
13.1. <rich:jQuery>
13.1.1. Basic usage
13.1.2. Defining a selector
13.1.3. Event handlers
13.1.4. Timed queries
13.1.5. Named queries
13.1.6. Dynamic rendering
13.1.7. Reference data
14. Functions
14.1. rich:clientId
14.2. rich:component
14.3. rich:element
14.4. rich:findComponent
14.5. rich:isUserInRole

The Ajax components in the a4j library share common attributes to perform similar functionality. Most RichFaces components in the rich library that feature built-in Ajax support share these common attributes as well.

Most attributes have default values, so they need not be explicitly set for the component to function in its default state. These attributes can be altered to customize the behavior of the component if necessary.

The render attribute provides a reference to one or more areas on the page that need updating after an Ajax interaction. It uses the UIComponent.findComponent() algorithm to find the components in the component tree using their id attributes as a reference. Components can be referenced by their id attribute alone, or by a hierarchy of components' id attributes to make locating components more efficient. Example 2.1, “render example” shows both ways of referencing components. Each command button will correctly render the referenced panel grids, but the second button locates the references more efficiently with explicit hierarchy paths.


The value of the render attribute can also be an expression written using JavaServer Faces' Expression Language (EL); this can either be a Set, Collection, Array, or String.

rendered attributes

A common problem with using render occurs when the referenced component has a rendered attribute. JSF does not mark the place in the browser's Document Object Model (DOM) where the rendered component would be placed in case the rendered attribute returns false. As such, when RichFaces sends the render code to the client, the page does not update as the place for the update is not known.

To work around this issue, wrap the component to be rendered in an <a4j:outputPanel> with layout="none". The <a4j:outputPanel> will receive the update and render the component as required.

RichFaces allows for Ajax-enabled JSF applications to be developed without using any additional JavaScript code. However it is still possible to invoke custom JavaScript code through Ajax events.

This chapter covers those attributes and features that are common to many of the components in the tag libraries.

This chapter details the basic components that respond to a user action and submit an Ajax request.

The <a4j:actionParam> behavior combines the functionality of the JavaServer Faces (JSF) components <f:param> and <f:actionListener>.

The <rich:componentControl> allows JavaScript API functions to be called on components after defined events. Initialization variants and activation events can be customized, and parameters can be passed to the target component.

The <a4j:jsFunction> component allows Ajax requests to be performed directly from JavaScript code, and server-side data to be invoked and returned in JavaScript Object Notation (JSON) format to use in client-side JavaScript calls.

This chapter details those components in the a4j tag library which define an area used as a container or wrapper for other components.

The <a4j:include> component allows one view to be included as part of another page. This is useful for applications where multiple views might appear on the one page, with navigation between the views. Views can use partial page navigation in Ajax mode, or standard JSF navigation for navigation between views.

The viewId attribute is required to reference the resource that will be included as a view on the page. It uses a full context-relative path to point to the resource, similar to the paths used for the <from-view-id> and <to-view-id> tags in the faces-config.xml JSF navigation rules.

Example 6.1. A wizard using <a4j:include>

The page uses <a4j:include> to include the first step of the wizard:


<h:panelGrid width="100%" columns="2">
    <a4j:keepAlive beanName="profile" />
    <rich:panel>
        <f:facet name="header">
        <h:outputText value="A wizard using a4j:include" />
        </f:facet>
        <h:form>
            <a4j:include viewId="/richfaces/include/examples/wstep1.xhtml" />
        </h:form>
    </rich:panel>
</h:panelGrid>

The first step is fully contained in a separate file, wstep1.xhtml. Subsequent steps are set up similarly with additional Previous buttons.


<ui:composition xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:a4j="http://richfaces.org/a4j"
      xmlns:rich="http://richfaces.org/rich">
    
    <div style="position:relative;height:140px">
        <h:panelGrid rowClasses="s1row" columns="3" columnClasses="wfcol1,wfcol2,wfcol3">
            <h:outputText value="First Name:" />
            <h:inputText id="fn" value="#{profile.firstName}" label="First Name" required="true" />
            <rich:message  for="fn" />
            
            <h:outputText value="Last Name:" />
            <h:inputText  id="ln" value="#{profile.lastName}"  label="Last Name"  required="true" />
            <rich:message  for="ln" />
        </h:panelGrid>
        <div class="navPanel" style="width:100%;">
            <a4j:commandButton style="float:right" action="next" value="Next &gt;&gt;"/>
        </div>
    </div>
</ui:composition>

The navigation is defined in the faces-config.xml configuration file:


<navigation-rule> 
   <from-view-id>/richfaces/include/examples/wstep1.xhtml</from-view-id> 
   <navigation-case> 
      <from-outcome>next</from-outcome> 
      <to-view-id>/richfaces/include/examples/wstep2.xhtml</to-view-id> 
   </navigation-case> 
</navigation-rule>  
<navigation-rule> 
   <from-view-id>/richfaces/include/examples/wstep2.xhtml</from-view-id> 
   <navigation-case> 
      <from-outcome>previous</from-outcome> 
      <to-view-id>/richfaces/include/examples/wstep1.xhtml</to-view-id> 
   </navigation-case> 
   <navigation-case> 
      <from-outcome>next</from-outcome> 
      <to-view-id>/richfaces/include/examples/finalStep.xhtml</to-view-id> 
   </navigation-case> 
</navigation-rule>  
<navigation-rule> 
   <from-view-id>/richfaces/include/examples/finalStep.xhtml</from-view-id> 
   <navigation-case> 
      <from-outcome>previous</from-outcome> 
      <to-view-id>/richfaces/include/examples/wstep2.xhtml</to-view-id> 
   </navigation-case> 
</navigation-rule> 

This chapter covers those components that validate user input. The components enhance JSF validation capabilities with Ajax support and the use of Hibernate validators.

The <rich:ajaxValidator> component provides Ajax validation for JSF inputs. It is added as a child component to a JSF tag, and the event attribute specifies when to trigger the validation.


The <rich:ajaxValidator> component can also work with custom validators made using the JSF Validation API in the javax.faces.validator package, or with Hibernate Validator. Refer to the Hibernate Validator documentation for details on how to use Hibernate Validator.

Example 7.2. Using <rich:ajaxValidator> with Hibernate Validator

This example shows the use of <rich:ajaxValidator> with Hibernate Validator. It validates the entered name, email, and age.


<h:form id="ajaxValidatorForm2">
    <rich:panel>
        <f:facet name="header">
            <h:outputText value="User Info:" />
        </f:facet>
        <h:panelGrid  columns="3">
            <h:outputText value="Name:" />
            <h:inputText value="#{validationBean.name}" id="name" required="true">
                <rich:ajaxValidator event="onblur" />
            </h:inputText>
            <rich:message for="name" />
            <h:outputText value="Email:" />
            <h:inputText value="#{validationBean.email}" id="email">
                <rich:ajaxValidator event="onblur" />
            </h:inputText>
            <rich:message for="email" />
            <h:outputText value="Age:" />
            <h:inputText value="#{validationBean.age}" id="age">
                <rich:ajaxValidator event="onblur" />
            </h:inputText>
            <rich:message for="age" />
        </h:panelGrid>
    </rich:panel>
</h:form>

The validation is performed using the ValidationBean class:

package org.richfaces.demo.validation;


import org.hibernate.validator.Email;
import org.hibernate.validator.Length;
import org.hibernate.validator.Max;
import org.hibernate.validator.Min;
import org.hibernate.validator.NotEmpty;
import org.hibernate.validator.NotNull;
import org.hibernate.validator.Pattern;
public class ValidationBean {
    private String progressString="Fill the form in";
    
    @NotEmpty
    @Pattern(regex=".*[^\\s].*", message="This string contains only spaces")
    @Length(min=3,max=12)
    private String name;
    @Email
    @NotEmpty
    private String email;
    
    @NotNull
    @Min(18)
    @Max(100)
    private Integer age;
    
    public ValidationBean() {
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public Integer getAge() {
        return age;
    }
    public void setAge(Integer age) {
        this.age = age;
    }
    public void success() {
        setProgressString(getProgressString() + "(Stored successfully)");
    }
    public String getProgressString() {
        return progressString;
    }
    public void setProgressString(String progressString) {
        this.progressString = progressString;
    }
}

Figure 7.1. <rich:ajaxValidator> example result



The <rich:beanValidator> component provides model-based constraints using Hibernate Validator. This allows Hibernate Validator to be used similar to its use with Seam-based applications.

The summary attribute is used for displaying messages about validation errors.

Example 7.3. <rich:beanValidator> example

This example shows the bean-based validation of a simple form, containing the user's name, email, and age. The <rich:beanValidator> component is defined in the same way as for JSF validators.


<h:form id="beanValidatorForm">
    <rich:panel>
        <f:facet name="header">
            <h:outputText value="#{validationBean.progressString}" id="progress"/>
        </f:facet>
        <h:panelGrid columns="3">
            <h:outputText value="Name:" />
            <h:inputText value="#{validationBean.name}" id="name">
                <rich:beanValidator summary="Invalid name"/>
            </h:inputText>
            <rich:message for="name" />
            <h:outputText value="Email:" />
            <h:inputText value="#{validationBean.email}" id="email">
                <rich:beanValidator summary="Invalid email"/>
            </h:inputText>
            <rich:message for="email" />
            <h:outputText value="Age:" />
            <h:inputText value="#{validationBean.age}" id="age">
                <rich:beanValidator summary="Wrong age"/>
            </h:inputText>
            <rich:message for="age" />
            <f:facet name="footer">
                <a4j:commandButton value="Submit" action="#{validationBean.success}" reRender="progress"/>
            </f:facet>
        </h:panelGrid>
    </rich:panel>
</h:form>

The accompanying bean contains the validation data:

package org.richfaces.demo.validation;


import org.hibernate.validator.Email;
import org.hibernate.validator.Length;
import org.hibernate.validator.Max;
import org.hibernate.validator.Min;
import org.hibernate.validator.NotEmpty;
import org.hibernate.validator.NotNull;
import org.hibernate.validator.Pattern;
public class ValidationBean {
    private String progressString="Fill the form in";
    
    @NotEmpty
    @Pattern(regex=".*[^\\s].*", message="This string contains only spaces")
    @Length(min=3,max=12)
    private String name;
    @Email
    @NotEmpty
    private String email;
    
    @NotNull
    @Min(18)
    @Max(100)
    private Integer age;
    
    public ValidationBean() {
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public Integer getAge() {
        return age;
    }
    public void setAge(Integer age) {
        this.age = age;
    }
    public void success() {
        setProgressString(getProgressString() + "(Stored successfully)");
    }
    public String getProgressString() {
        return progressString;
    }
    public void setProgressString(String progressString) {
        this.progressString = progressString;
    }
}

Figure 7.2. <rich:beanValidator> example result



The <rich:graphValidator> component is used to wrap a group of input components for overall validation with Hibernate Validators. This is different from the <rich:beanValidator> component, which is used as a child element to individual input components.

The summary attribute is used for displaying messages about validation errors.

Example 7.4. <rich:graphValidator> example

This example shows the validation of a simple form, containing the user's name, email, and age. The <rich:graphValidator> component wraps the input components to validate them together.


<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich">

    <h:form id="graphValidatorForm">
        <a4j:region renderRegionOnly="true">
            <rich:panel id="panel">
                <f:facet name="header">
                    <h:outputText value="User Info:" />
                </f:facet>
                <rich:graphValidator summary="Invalid values: ">
                    <h:panelGrid columns="3">
                        <h:outputText value="Name:" />
                        <h:inputText value="#{validationBean.name}" id="name">
                            <f:validateLength minimum="2" />
                        </h:inputText>
                        <rich:message for="name" />
                        <h:outputText value="Email:" />
                        <h:inputText value="#{validationBean.email}" id="email" />
                        <rich:message for="email" />
                        <h:outputText value="Age:" />
                        <h:inputText value="#{validationBean.age}" id="age" />
                        <rich:message for="age" />
                    </h:panelGrid>
                </rich:graphValidator>
                <a4j:commandButton value="Store changes" />
            </rich:panel>
        </a4j:region>
    </h:form>
</ui:composition>

The accompanying bean contains the validation data:

package org.richfaces.demo.validation;


import org.hibernate.validator.Email;
import org.hibernate.validator.Length;
import org.hibernate.validator.Max;
import org.hibernate.validator.Min;
import org.hibernate.validator.NotEmpty;
import org.hibernate.validator.NotNull;
import org.hibernate.validator.Pattern;
public class ValidationBean {
    private String progressString="Fill the form in";
    
    @NotEmpty
    @Pattern(regex=".*[^\\s].*", message="This string contains only spaces")
    @Length(min=3,max=12)
    private String name;
    @Email
    @NotEmpty
    private String email;
    
    @NotNull
    @Min(18)
    @Max(100)
    private Integer age;
    
    public ValidationBean() {
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public Integer getAge() {
        return age;
    }
    public void setAge(Integer age) {
        this.age = age;
    }
    public void success() {
        setProgressString(getProgressString() + "(Stored successfully)");
    }
    public String getProgressString() {
        return progressString;
    }
    public void setProgressString(String progressString) {
        this.progressString = progressString;
    }
}

Figure 7.3. <rich:graphValidator> example result



The optional value attribute can be used to define a value bound to the bean. The bean properties are then validated again after the model has been updated.

Example 7.5. Using the value attribute



    <h:form id="graphValidatorForm2">
    <a4j:region renderRegionOnly="true">
        <rich:graphValidator summary="Invalid values: " value="#{dayStatistics}">
            <table>
                <thead>
                    <tr>
                        <th>Activity</th>
                        <th>Time</th>
                    </tr>
                </thead>
                <tbody>
                    <a4j:repeat value="#{dayStatistics.dayPasstimes}" var="pt"
                        id="table">
                        <tr>
                            <td align="center" width="100px"><h:outputText
                                value="#{pt.title}" /></td>
                            <td align="center" width="100px"><rich:inputNumberSpinner
                                minValue="0" maxValue="24" value="#{pt.time}" id="time">
                            </rich:inputNumberSpinner></td>
                            <td><rich:message for="time" /></td>
                        </tr>
                    </a4j:repeat>
                </tbody>
            </table>
        </rich:graphValidator>
        <a4j:commandButton value="Store my details"
            actionListener="#{dayStatistics.store}" reRender="panel" />
        <rich:messages infoClass="green" errorClass="red" />
    </a4j:region>
</h:form>

    

Figure 7.4. Result from using the value attribute



This chapter covers those components that manage the processing of information, requests, and updates.

The <a4j:queue> component manages a queue of Ajax requests to control message processing.

The <a4j:status> component displays the status of current Ajax requests; the status can be either in progress or complete.

The <a4j:status> component works for each Ajax component inside the local region. If no region is defined, every request made on the page will activate the <a4j:status> component. Alternatively, the <a4j:status> component can be linked to specific components in one of two ways:

Example 8.3. Updating a common <a4j:status> component


<a4j:region id="extr">
    <h:form>
        <h:outputText value="Status:" />
        <a4j:status id="commonstatus" startText="In Progress...." stopText="" />

        <a4j:region id="intr">
            <h:panelGrid columns="2">
                <h:outputText value="Name" />
                <h:inputText id="name" value="#{userBean.name}">
                    <a4j:support event="onkeyup" reRender="out" status="commonstatus" />
                </h:inputText>

                <h:outputText value="Job" />
                <h:inputText id="job" value="#{userBean.job}">
                    <a4j:support event="onkeyup" reRender="out" status="commonstatus" />
                </h:inputText>

                <h:panelGroup /> 

            </h:panelGrid>
        </a4j:region>
        <a4j:region>
            <br />
            <rich:spacer height="5" />
            <b><h:outputText id="out"
                value="Name: #{userBean.name}, Job: #{userBean.job}" /></b>
            <br />
            <rich:spacer height="5" />
            <br />
            <a4j:commandButton ajaxSingle="true" value="Clean Up Form"
                reRender="name, job, out" status="commonstatus">
                <a4j:actionparam name="n" value="" assignTo="#{userBean.name}" />
                <a4j:actionparam name="j" value="" assignTo="#{userBean.job}" />
            </a4j:commandButton>
        </a4j:region>

    </h:form>
</a4j:region>

Table of Contents

9. Rich inputs
9.1. <rich:autocomplete>
9.1.1. Basic usage
9.1.2. Interactivity options
9.1.3. Reference data
9.2. <rich:calendar>
9.2.1. Basic usage
9.2.2. Using a data model
9.2.3. Behavior and appearance
9.2.4. Time of day
9.2.5. <rich:calendar> events
9.2.6. Reference data
9.3. <rich:inplaceInput>
9.3.1. Basic usage
9.3.2. Interactivity options
9.3.3. Reference data
9.4. <rich:inplaceSelect>
9.4.1. Basic usage
9.4.2. Interactivity options
9.4.3. <rich:inplaceSelect> events
9.4.4. Reference data
9.5. <rich:inputNumberSlider>
9.5.1. Basic usage
9.5.2. Interactivity options
9.5.3. Reference data
9.6. <rich:inputNumberSpinner>
9.6.1. Basic usage
9.6.2. Interactivity options
9.6.3. Reference data
9.7. <rich:select>
9.7.1. Basic usage
9.7.2. Using <rich:select> as a combo-box
9.7.3. Reference data
10. Panels and containers
10.1. <rich:panel>
10.1.1. Basic usage
10.1.2. Adding a header
10.1.3. Reference data
10.2. <rich:popupPanel>
10.2.1. Basic usage
10.2.2. Showing and hiding the pop-up
10.2.3. Modal and non-modal panels
10.2.4. Size and positioning
10.2.5. Contents of the pop-up
10.2.6. Header and controls
10.2.7. Reference data
10.3. <rich:accordion>
10.3.1. Basic usage
10.3.2. Switching panels
10.3.3. <rich:accordion> client-side events
10.3.4. <rich:accordion> server-side events
10.3.5. Reference data
10.4. <rich:accordionItem>
10.4.1. Basic usage
10.4.2. <rich:accordionItem> client-side events
10.4.3. Reference data
10.5. <rich:collapsiblePanel>
10.5.1. Basic usage
10.5.2. Expanding and collapsing the panel
10.5.3. Appearance
10.5.4. <rich:collapsiblePanel> server-side events
10.5.5. Reference data
10.6. <rich:tab>
10.6.1. Basic usage
10.6.2. Header labeling
10.6.3. Switching tabs
10.6.4. <rich:tab> client-side events
10.6.5. Reference data
10.7. <rich:tabPanel>
10.7.1. Switching panels
10.7.2. <rich:tabPanel> client-side events
10.7.3. <rich:tabPanel> server-side events
10.7.4. Reference data
10.8. <rich:toggleControl>
10.8.1. Basic usage
10.8.2. Specifying the next state
10.8.3. Reference data
10.9. <rich:togglePanel>
10.9.1. Basic usage
10.9.2. Toggling between components
10.9.3. Reference data
10.10. <rich:togglePanelItem>
10.10.1. Reference data
11. Tables and grids
11.1. <a4j:repeat>
11.1.1. Basic usage
11.1.2. Limited views and partial updates
11.1.3. Reference data
11.2. <rich:column>
11.2.1. Basic usage
11.2.2. Spanning columns
11.2.3. Spanning rows
11.2.4. Reference data
11.3. <rich:columnGroup>
11.3.1. Complex headers
11.3.2. Reference data
11.4. <rich:dataGrid>
11.4.1. Basic usage
11.4.2. Customizing the grid
11.4.3. Patial updates
11.4.4. Reference data
11.5. <rich:dataTable>
11.5.1. Basic usage
11.5.2. Customizing the table
11.5.3. Partial updates
11.5.4. Reference data
11.6. <rich:extendedDataTable>
11.6.1. Basic usage
11.6.2. Table appearance
11.6.3. Extended features
11.6.4. Reference data
11.7. <rich:list>
11.7.1. Basic usage
11.7.2. Type of list
11.7.3. Bullet and numeration appearance
11.7.4. Customizing the list
11.7.5. Reference data
11.8. Table filtering
11.9. Table sorting
12. Output and messages
12.1. <rich:progressBar>
12.1.1. Basic usage
12.1.2. Customizing the appearance
12.1.3. Using set intervals
12.1.4. Update mode
12.1.5. Reference data
12.2. <rich:toolTip>
12.2.1. Basic usage
12.2.2. Attaching the tool-tip to another component
12.2.3. Appearance
12.2.4. Update mode
12.2.5. <rich:toolTip> client-side events
12.2.6. Reference data
13. Layout and appearance
13.1. <rich:jQuery>
13.1.1. Basic usage
13.1.2. Defining a selector
13.1.3. Event handlers
13.1.4. Timed queries
13.1.5. Named queries
13.1.6. Dynamic rendering
13.1.7. Reference data
14. Functions
14.1. rich:clientId
14.2. rich:component
14.3. rich:element
14.4. rich:findComponent
14.5. rich:isUserInRole

Documentation in development

Some concepts covered in this chapter may refer to the previous version of Richfaces, version 3.3.3. This chapter is scheduled for review to ensure all information is up to date.

This chapter details rich components for user input and interaction.

The <rich:autocomplete> component is an auto-completing input-box with built-in Ajax capabilities. It supports client-side suggestions, browser-like selection, and customization of the look and feel.

To attach an auto-completion behavior to other components, use the <rich:autocompleteBehavior> behavior. Refer to ??? for full details on the <rich:autocompleteBehavior> behavior.

Figure 9.1. <rich:autocomplete>


The <rich:calendar> component allows the user to enter a date and time through an in-line or pop-up calendar. The pop-up calendar can navigate through months and years, and its look and feel can be highly customized.

Figure 9.2. <rich:calendar>


The <rich:calendar> component is presented as a pop-up by default, appearing as a text field with a button to expand the full pop-up calendar. To render the calendar in-line on the page instead, set popup="false. This displays the full calendar without the text field or display button.

To change the appearance of the display button from the standard calendar icon, use the buttonIcon and buttonIconDisabled attributes to replace the icon with a specified file. Alternatively, use the buttonLabel attribute to display text on the button without an icon. If buttonLabel is specified then both the buttonIcon and buttonIconDisabled attributes are ignored. To hide the text field box, set showInput="false".

To change the default position at which the pop-up calendar is shown relative to the text field and button, use the jointPoint and direction attributes. The jointPoint attribute refers to the corner of the text field and button with which the calendar will be aligned and the direction specifies which direction the pop-up calendar will span relative to the joint point. The default settings are jointPoint="bottom-left" and direction="bottom-right", causing the pop-up calendar to align with the bottom-left corner of the text field and span to the bottom-right, underneath the text field and button. The diagram shows the joint points and directions that can be used. Alternatively, set both jointPoint and direction attributes to auto to allow smart pop-up positioning. Figure 9.3, “Pop-up positioning” shows the different possible settings for the jointPoint and direction attributes.

Pop-up positioning is determined using the jointPoint and direction attributes. Values for the jointPoint attribute are shown in red, while values for the direction attribute are shown in black.

Figure 9.3. Pop-up positioning


The calendar features a Today button for locating today's date on the calendar. This can be set to three different values using the todayControlMode attribute:

  • hidden, which does not display the button;

  • select, the default setting, which scrolls the calendar to the current month and selects today's date; and

  • scroll, which scrolls the calendar to the current month but does not select today's date.

To make the entire calendar read-only, set readonly="true". This allows months and years to be browsed through with the arrow controls, but dates and times cannot be selected.

The <rich:inplaceInput> component allows information to be entered in-line in blocks of text, improving readability of the text. Multiple input regions can be navigated with keyboard navigation. The component has three functional states: the "view" state, where the component displays its initial setting, such as "click to edit"; the "edit" state, where the user can input text; and the "changed" state, where the new value for the component has been confirmed but can be edited again if required.

The <rich:inplaceSelect> component is similar to the <rich:inplaceInput> component, except that the <rich:inplaceSelect> component uses a drop-down selection box to enter text instead of a regular text field. Changes can be rendered either in-line or for the whole block, and inputs can be focused with keyboard navigation. The component has three functional states: the "view" state, where the component displays its initial setting, such as "click to edit"; the "edit" state, where the user can select a value from a drop-down list; and the "changed" state, where the new value for the component has been confirmed but can be edited again if required.

Figure 9.4. <rich:inplaceSelect>


The <rich:inputNumberSlider> component provides a slider for changing numerical values. Optional features include control arrows to step through the values, a tool-tip to display the value while sliding, and a text field for typing the numerical value which can then be validated against the slider's range.

Figure 9.5. <rich:inputNumberSlider>


The <rich:inputNumberSpinner> component is a single-line input field with buttons to increase and decrease a numerical value. The value can be changed using the corresponding directional keys on a keyboard, or by typing into the field.

Figure 9.6. <rich:inputNumberSpinner>


The <rich:select> component provides a drop-down list box for selecting a single value from multiple options. The component supports keyboard navigation and can optionally accept typed input as a combo-box.

Figure 9.7. <rich:select>


Documentation in development

Some concepts covered in this chapter may refer to the previous version of Richfaces, version 3.3.3. This chapter is scheduled for review to ensure all information is up to date.

This chapter details those components which act as panels and containers to hold groups of other components.

The <rich:popupPanel> component provides a pop-up panel or window that appears in front of the rest of the application. The <rich:popupPanel> component functions either as a modal window which blocks interaction with the rest of the application while active, or as a non-modal window. It can be positioned on the screen, dragged to a new position by the user, and re-sized.

If show="true" then the pop-up panel will display when the page is first loaded.

The <rich:popupPanel> component can be shown and hidden manually using the show() and hide() methods from the JavaScript API. These can be implemented using two different approaches:

For explicit referencing when using the functions, the component can be given an id identifier. The component can, however, be referenced using other means, such as through a selector.

Example 10.2, “<rich:popupPanel> example” demonstrates basic use of both the <rich:componentControl> component and the rich:component function to show and hide the <rich:popupPanel> component.


The pop-up panel can be both re-sized and re-positioned by the user. The minimum possible size for the panel can be set with the minWith and minHeight attributes. These abilities can be deactivated by setting resizable or movable to false as necessary.

The pop-up panel can be automatically sized when it is shown if the autosized attribute is set to true.

The <rich:popupPanel> component is usually rendered in front of any other objects on the page. This is achieved by attaching the component to the <body> element of the page, and setting a very high "z-index" (the stack order of the object). This approach is taken because relatively-positioned elements could still overlap the pop-up panel if they exist at higher levels of the DOM hierarchy, even if their z-index is less than the <rich:popupPanel> component. However, to avoid form limitation of the pop-up panel on pages where no such elements exist, the <rich:popupPanel> component can be reattached to its original DOM element by setting domElementAttachment to either parent or form.

Embedded objects inserted into the HTML with the <embed> tag will typically be rendered in front of a <rich:popupPanel> component. The <rich:popupPanel> component can be forcibly rendered in front of these objects by setting overlapEmbedObjects="true".

The <rich:accordion> is a series of panels stacked on top of each other, each collapsed such that only the header of the panel is showing. When the header of a panel is clicked, it is expanded to show the content of the panel. Clicking on a different header will collapse the previous panel and epand the selected one. Each panel contained in a <rich:accordion> component is a <rich:accordionItem> component.

Figure 10.4. A <rich:accordion> component containing three <rich:accordionItem> components


The <rich:collapsiblePanel> component is a collapsible panel that shows or hides content when the header bar is activated. It is a simplified version of <rich:togglePanel> component.

Figure 10.6. <rich:collapsiblePanel>


The <rich:tab> component represents an individual tab inside a <rich:tabPanel> component, including the tab's content. Clicking on the tab header will bring its corresponding content to the front of other tabs. Refer to Section 10.7, “<rich:tabPanel>” for details on the <rich:tabPanel> component.

Figure 10.7. A <rich:tabPanel> component containing three <rich:tab> components


The <rich:tabPanel> component provides a set of tabbed panels for displaying one panel of content at a time. The tabs can be highly customized and themed. Each tab within a <rich:tabPanel> container is a <rich:tab> component. Refer to Section 10.6, “<rich:tab>” for further details on the <rich:tab> component.

Figure 10.8. A <rich:tabPanel> component containing three <rich:tab> components


Form elements required

All <rich:tabPanel> components should be wrapped in a form element so that the contents of the tab are processed correctly during a tab change in either ajax or server mode.

Alternatively, the contents of a <rich:tab> component within the <rich:tabPanel> component could be wrapped in a form element, such that they will be processed using the inner submitting component only. In this case, the <rich:tabPanel> component will automatically add form tags around the tab's contents, and the contents will not be processed during switching.

The <rich:toggleControl> behavior can be attached to any interface component. It works with a <rich:togglePanel> component to switch between different <rich:togglePanelItem> components.

Refer to Section 10.9, “<rich:togglePanel>” and Section 10.10, “<rich:togglePanelItem>” for details on how to use the components together.

The <rich:togglePanel> component is a wrapper for multiple <rich:togglePanelItem> components. Each child component is displayed after being activated with the <rich:toggleControl> behavior.

Refer to Section 10.8, “<rich:toggleControl>” and Section 10.9, “<rich:togglePanel>” for details on how to use the components together.

The <rich:togglePanel> component is used as a base for the other switchable components, the <rich:accordion> component and the <rich:tabPanel> component. It provides an abstract switchable component without any associated markup. As such, the <rich:togglePanel> component could be customized to provide a switchable component when neither an accordion component or a tab panel component is appropriate.

Documentation in development

Some concepts covered in this chapter may refer to the previous version of Richfaces, version 3.3.3. This chapter is scheduled for review to ensure all information is up to date.

This chapter covers all components related to the display of tables and grids.

The <a4j:repeat> component is used to iterate changes through a repeated collection of components. It allows specific rows of items to be updated without sending Ajax requests for the entire collection. The <a4j:repeat> component forms the basis for many of the tabular components detailed in Chapter 11, Tables and grids.

The <a4j:repeat> component uses other attributes common to iteration components, such as the first attribute for specifying the first item for iteration, and the rows attribute for specifying the number of rows of items to display.

Specific cells, rows, and columns can be updated without sending Ajax requests for the entire collection. Components that cause the change can specify which part of the table to update through the render attribute. The render attribute specifies which part of a table to update:

Alternatively, keywords can be used with the render attribute:

The <rich:column> component facilitates columns in a table. It supports merging columns and rows, sorting, filtering, and customized skinning.

The <rich:columnGroup> component combines multiple columns in a single row to organize complex parts of a table. The resulting effect is similar to using the breakBefore attribute of the <rich:column> component, but is clearer and easier to follow in the source code.

The <rich:columnGroup> can also be used to create complex headers in a table. Example 11.5, “Complex headers using column groups” and the resulting Figure 11.4, “Complex headers using column groups” demonstrate how complex headers can be achieved.

Example 11.5. Complex headers using column groups


The <rich:dataGrid> component is used to arrange data objects in a grid. Values in the grid can be updated dynamically from the data model, and Ajax updates can be limited to specific rows. The component supports header, footer, and caption facets.

The <rich:dataGrid> component is similar in function to the JavaServer Faces <h:panelGrid> component. However, the <rich:dataGrid> component additionally allows iteration through the data model rather than just aligning child components in a grid layout.

Figure 11.5. The <rich:dataGrid> component


The <rich:dataTable> component is used to render a table, including the table's header and footer. It works in conjunction with the <rich:column> and <rich:columnGroup> components to list the contents of a data model.

The first attribute specifies which item in the data model to start from, and the rows attribute specifies the number of items to list. The header, footer, and caption facets can be used to display text, and to customize the appearance of the table through skinning. demonstrates a simple table implementation.


For details on filtering and sorting data tables, refer to Section 11.8, “Table filtering” and Section 11.9, “Table sorting”.

The <rich:extendedDataTable> component builds on the functionality of the <rich:dataTable> component, adding features such as data scrolling, row and column selection, and rearranging of columns.

The <rich:extendedDataTable> component includes the following attributes not included in the <rich:dataTable> component:

frozenColumnsonselectionchangeselectionMode
heightselectedClasstableState
noDataLabelselection 

The <rich:extendedDataTable> component does not include the following attributes available with the <rich:dataTable> component:

Example 11.8. <rich:extendedDataTable> example


<rich:extendedDataTable id="edt" value="#{extendedDT.dataModel}" var="edt" width="500px" height="500px" selectedClass="dataTableSelectedRow" sortMode="single" selectionMode="multi" selection="#{extendedDT.selection}" rowKeyVar="rkvar" tableState="#{extendedDT.tableState}">
    <rich:column id="id" headerClass="dataTableHeader" width="50" label="Id" sortable="true" sortBy="#{edt.id}" sortIconAscending="dataTableAscIcon" sortIconDescending="dataTableDescIcon">
        <f:facet name="header">
            <h:outputText value="Id" />
        </f:facet>
        <h:outputText value="#{edt.id}" />
    </rich:column>
    <rich:column id="name" width="300" headerClass="dataTableHeader" label="Name" sortable="true" sortBy="#{edt.name}" sortIconAscending="dataTableAscIcon" sortIconDescending="dataTableDescIcon" filterBy="#{edt.name}" filterEvent="onkeyup" visible="false"> 
        <f:facet name="header"> 
            <h:outputText value="Name" />
        </f:facet>
        <h:outputText value="#{edt.name}" />
    </rich:column>
    <rich:column id="date" width="100" headerClass="dataTableHeader" label="Date" sortable="true" comparator="#{extendedDT.dateComparator}" sortIconAscending="dataTableAscIcon" sortIconDescending="dataTableDescIcon">
        <f:facet name="header">
            <h:outputText value="Date" />
        </f:facet>
        <h:outputText value="#{edt.date}"><f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss" />
        </h:outputText>
    </rich:column>
    <rich:column id="group" width="50" headerClass="dataTableHeader" label="Group" sortable="true" sortBy="#{edt.group}" sortIconAscending="dataTableAscIcon" sortIconDescending="dataTableDescIcon">
        <f:facet name="header">
            <h:outputText value="Group" />
        </f:facet>
        <h:outputText value="#{edt.group}" />
    </rich:column>
</rich:extendedDataTable>

Figure 11.8. <rich:extendedDataTable> example



Example 11.8, “<rich:extendedDataTable> example” shows an example extended data table. The implementation features a scrolling data table, selection of one or more rows, sorting by columns, grouping by column, and a filter on the Name column.

The <rich:list> component renders a list of items. The list can be an numerically ordered list, an unordered bullet-point list, or a data definition list. The component uses a data model for managing the list items, which can be updated dynamically.

Documentation in development

Some concepts covered in this chapter may refer to the previous version of Richfaces, version 3.3.3. This chapter is scheduled for review to ensure all information is up to date.

Read this chapter for details on components that display messages and other feedback to the user.

The <rich:progressBar> component displays a progress bar to indicate the status of a process to the user. It can update either through Ajax or on the client side, and the look and feel can be fully customized.

Figure 12.1. <rich:progressBar>


By default, the minimum value of the progress bar is 0 and the maximum value of the progress bar is 100. These values can be customized using the minValue and maxValue attributes respectively.

The progress bar can be labeled in one of two ways:

For labeling, the <rich:progressBar> component recognizes three macro-substitution parameters:


Additionally, you can use the {param} parameter to specify any custom parameters you require. Define the parameters in the bean for the progress method, then reference it with the <rich:progressBar> component's parameters attribute, as shown in Example 12.5, “Using the param parameter”.


To define customized initial and complete states for the progress bar, use the initial and complete facets. The initial facet displays when the progress value is less than or equal to the minimum value, and the complete facet displays when the progress value is greater than or equal to the maximum value.


The <rich:toolTip> component provides an informational tool-tip. The tool-tip can be attached to any control and is displayed when hovering the mouse cursor over the control.

Figure 12.2. <rich:toolTip>


Documentation in development

Some concepts covered in this chapter may refer to the previous version of Richfaces, version 3.3.3. This chapter is scheduled for review to ensure all information is up to date.

Read this chapter to alter the layout and appearance of web applications using special components.

The <rich:jQuery> component applies styles and custom behavior to both JSF (JavaServer Faces) objects and regular DOM (Document Object Model) objects. It uses the jQuery JavaScript framework to add functionality to web applications.

Named queries are given a name such that they can be triggered by other functions or handlers. Use the name attribute to name the query. The query can then be accessed as though it were a JavaScript function using the specified name attribute as the function name.

Calls to the function must pass a direct reference (this) to the calling object as a parameter. This is treated the same as an item defined through the selector attribute.

If the function requires extra parameters itself, these are provided in JavaScript Object Notation (JSON) syntax as a second parameter in the JavaScript call. The options namespace is then used in the <rich:jQuery> query to access the passed function parameters. Example 13.3, “Calling a <rich:jQuery> component as a function” demonstrates the use of the name attribute and how to pass function parameters through the JavaScript calls.


Read this chapter for details on special functions for use with particular components. Using JavaServer Faces Expression Language (JSF EL), these functions can be accessed through the data attribute of components. Refer to Section 2.5.7, “data” for details on the data attribute.