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:actionParam>
4.1.1. Basic usage
4.1.2. Interoperability
4.1.3. Reference data
4.2. <a4j:commandButton>
4.2.1. Basic usage
4.2.2. Reference data
4.3. <a4j:commandLink>
4.3.1. Basic usage
4.3.2. Reference data
4.4. <rich:componentControl>
4.4.1. Basic usage
4.4.2. Attaching to a component
4.4.3. Parameters and JavaScript
4.4.4. Timing
4.4.5. Reference data
4.5. <a4j:jsFunction>
4.5.1. Basic usage
4.5.2. Parameters and JavaScript
4.5.3. Reference data
4.6. <a4j:poll>
4.6.1. Timing options
4.6.2. Reference data
4.7. <a4j:push>
4.7.1. Timing options
4.7.2. Reference data
4.8. <a4j:ajax>
4.8.1. 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:inplaceInput>
9.2.1. Basic usage
9.2.2. Interactivity options
9.2.3. Reference data
9.3. <rich:inplaceSelect>
9.3.1. Basic usage
9.3.2. Interactivity options
9.3.3. <rich:inplaceSelect> events
9.3.4. Reference data
9.4. <rich:inputNumberSlider>
9.4.1. Basic usage
9.4.2. Interactivity options
9.4.3. Reference data
10. Panels and containers
10.1. <rich:accordion>
10.1.1. Basic usage
10.1.2. Switching panels
10.1.3. <rich:accordion> client-side events
10.1.4. <rich:accordion> server-side events
10.1.5. Reference data
10.2. <rich:accordionItem>
10.2.1. Basic usage
10.2.2. <rich:accordionItem> client-side events
10.2.3. Reference data
10.3. <rich:panel>
10.3.1. Basic usage
10.3.2. Adding a header
10.3.3. Reference data
10.4. <rich:popupPanel>
10.4.1. Basic usage
10.4.2. Showing and hiding the pop-up
10.4.3. Modal and non-modal panels
10.4.4. Size and positioning
10.4.5. Contents of the pop-up
10.4.6. Header and controls
10.4.7. Reference data
10.5. <rich:tab>
10.5.1. Basic usage
10.5.2. Switching tabs
10.5.3. <rich:tab> client-side events
10.5.4. Reference data
10.6. <rich:tabPanel>
10.6.1. Switching panels
10.6.2. Tab position and alignment
10.6.3. <rich:tabPanel> client-side events
10.6.4. <rich:tabPanel> server-side events
10.6.5. Reference data
10.7. <rich:toggleControl>
10.7.1. Basic usage
10.7.2. Specifying the next state
10.7.3. Reference data
10.8. <rich:togglePanel>
10.8.1. Basic usage
10.8.2. Toggling between components
10.8.3. Switching panels
10.8.4. Reference data
10.9. <rich:togglePanelItem>
10.9.1. Reference data
11. Tables and grids
11.1. <a4j:repeat>
11.1.1. Basic usage
11.1.2. 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. Customizing the list
11.7.4. Reference data
11.8. Table filtering
11.9. Table sorting
12. Layout and appearance
12.1. <rich:jQuery>
12.1.1. Basic usage
12.1.2. Calling a <richjQuery> as a JavaScript function
12.1.3. Dynamic rendering
12.1.4. Using the jQuery JavaScript framework
12.1.5. Reference data
13. Functions
13.1. rich:clientId
13.2. rich:component
13.3. rich:element
13.4. rich:findComponent
13.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:inplaceInput>
9.2.1. Basic usage
9.2.2. Interactivity options
9.2.3. Reference data
9.3. <rich:inplaceSelect>
9.3.1. Basic usage
9.3.2. Interactivity options
9.3.3. <rich:inplaceSelect> events
9.3.4. Reference data
9.4. <rich:inputNumberSlider>
9.4.1. Basic usage
9.4.2. Interactivity options
9.4.3. Reference data
10. Panels and containers
10.1. <rich:accordion>
10.1.1. Basic usage
10.1.2. Switching panels
10.1.3. <rich:accordion> client-side events
10.1.4. <rich:accordion> server-side events
10.1.5. Reference data
10.2. <rich:accordionItem>
10.2.1. Basic usage
10.2.2. <rich:accordionItem> client-side events
10.2.3. Reference data
10.3. <rich:panel>
10.3.1. Basic usage
10.3.2. Adding a header
10.3.3. Reference data
10.4. <rich:popupPanel>
10.4.1. Basic usage
10.4.2. Showing and hiding the pop-up
10.4.3. Modal and non-modal panels
10.4.4. Size and positioning
10.4.5. Contents of the pop-up
10.4.6. Header and controls
10.4.7. Reference data
10.5. <rich:tab>
10.5.1. Basic usage
10.5.2. Switching tabs
10.5.3. <rich:tab> client-side events
10.5.4. Reference data
10.6. <rich:tabPanel>
10.6.1. Switching panels
10.6.2. Tab position and alignment
10.6.3. <rich:tabPanel> client-side events
10.6.4. <rich:tabPanel> server-side events
10.6.5. Reference data
10.7. <rich:toggleControl>
10.7.1. Basic usage
10.7.2. Specifying the next state
10.7.3. Reference data
10.8. <rich:togglePanel>
10.8.1. Basic usage
10.8.2. Toggling between components
10.8.3. Switching panels
10.8.4. Reference data
10.9. <rich:togglePanelItem>
10.9.1. Reference data
11. Tables and grids
11.1. <a4j:repeat>
11.1.1. Basic usage
11.1.2. 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. Customizing the list
11.7.4. Reference data
11.8. Table filtering
11.9. Table sorting
12. Layout and appearance
12.1. <rich:jQuery>
12.1.1. Basic usage
12.1.2. Calling a <richjQuery> as a JavaScript function
12.1.3. Dynamic rendering
12.1.4. Using the jQuery JavaScript framework
12.1.5. Reference data
13. Functions
13.1. rich:clientId
13.2. rich:component
13.3. rich:element
13.4. rich:findComponent
13.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 those components which act as panels and containers to hold groups of other components.

The <rich:inplaceInput> component allows information to be entered in-line in blocks of text, improving readability of the text. 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 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.

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.

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: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.1. A <rich:accordion> component containing three <rich:accordionItem> 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: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.6, “<rich:tabPanel>” for details on the <rich:tabPanel> component.

Figure 10.6. 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.5, “<rich:tab>” for further details on the <rich:tab> component.

Figure 10.7. 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.8, “<rich:togglePanel>” and Section 10.9, “<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.7, “<rich:toggleControl>” and Section 10.8, “<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 <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.

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.9. <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.9, “<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.

By default, the list is displayed as an unordered bullet-point list. The type attribute is used to specify different list types:

unordered

The default presentation. The list is presented as a series of bullet-points, similar to the <ul> HTML element.

Figure 11.11. Unordered list


ordered

The list is presented as a numbered series of items, similar to the <ol> HTML element.

Figure 11.12. Ordered list


data

The list is presented as a series of data definitions. Part of the data model, specified as the term, is listed prominently. The other associated data is listed after each term.

Figure 11.13. Data definition list


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 without conflicting with the prototype.js library.

The query triggered by the <rich:jQuery> component is specified using the query attribute.

The query can be triggered in three different ways. Use the timing attribute to specify the point at which the query is triggered:


Any objects or lists of objects used in the query are specified using the selector attribute. The selector attribute references objects using the following method:

Because the selector attribute can be either an id identifier attribute or CSS selector syntax, conflicting values could arise. Example 12.3, “Avoiding syntax confusion” demonstrates how to use double backslashes to escape colon characters in id identifier values.


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.