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. submit
2.5.2. begin
2.5.3. click
2.5.4. success
2.5.5. complete
2.5.6. error
2.5.7. data
3. Common features
3.1. Positioning and appearance of components
3.2. Calling available JavaScript methods
I. Ajax control components
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:validator> client-side validation
7.1.1. Basic usage
7.1.2. Messages from client-side validators
7.1.3. Validation triggers
7.1.4. Ajax fall-backs
7.1.5. Reference data
7.2. <rich:graphValidator> object validation
7.2.1. Basic usage
7.2.2. 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. JavaScript API
8.3.4. Reference data
II. User interface components
9. Rich inputs
9.1. <rich:autocomplete>
9.1.1. Basic usage
9.1.2. Interactivity options
9.1.3. Customizing the filter
9.1.4. JavaScript API
9.1.5. Reference data
9.2. <rich:calendar>
9.2.1. Basic usage
9.2.2. Behavior and appearance
9.2.3. Time of day
9.2.4. Localization and formatting
9.2.5. Using a data model
9.2.6. Client-side customization
9.2.7. JavaScript API
9.2.8. Reference data
9.3. <rich:fileUpload>
9.3.1. Basic usage
9.3.2. Upload settings
9.3.3. Interactivity options
9.3.4. <rich:fileUpload> client-side events
9.3.5. Reference data
9.4. <rich:inplaceInput>
9.4.1. Basic usage
9.4.2. Interactivity options
9.4.3. JavaScript API
9.4.4. Reference data
9.5. <rich:inplaceSelect>
9.5.1. Basic usage
9.5.2. Interactivity options
9.5.3. JavaScript API
9.5.4. Reference data
9.6. <rich:inputNumberSlider>
9.6.1. Basic usage
9.6.2. Interactivity options
9.6.3. JavaScript API
9.6.4. Reference data
9.7. <rich:inputNumberSpinner>
9.7.1. Basic usage
9.7.2. Interactivity options
9.7.3. JavaScript API
9.7.4. Reference data
9.8. <rich:select>
9.8.1. Basic usage
9.8.2. Advanced options
9.8.3. Using manual input
9.8.4. JavaScript API
9.8.5. 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:accordion>
10.2.1. Basic usage
10.2.2. Switching panels
10.2.3. <rich:accordion> client-side events
10.2.4. <rich:accordion> server-side events
10.2.5. JavaScript API
10.2.6. Reference data
10.2.7. <rich:accordionItem>
10.3. <rich:collapsiblePanel>
10.3.1. Basic usage
10.3.2. Expanding and collapsing the panel
10.3.3. Appearance
10.3.4. <rich:collapsiblePanel> server-side events
10.3.5. JavaScript API
10.3.6. 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. JavaScript API
10.4.8. Reference data
10.5. <rich:tabPanel>
10.5.1. Switching panels
10.5.2. <rich:tabPanel> client-side events
10.5.3. <rich:tabPanel> server-side events
10.5.4. JavaScript API
10.5.5. Reference data
10.5.6. <rich:tab>
10.6. <rich:togglePanel>
10.6.1. Basic usage
10.6.2. Toggling between components
10.6.3. JavaScript API
10.6.4. Reference data
10.6.5. <rich:toggleControl>
10.6.6. <rich:togglePanelItem>
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:dataTable>
11.2.1. Basic usage
11.2.2. Customizing the table
11.2.3. Partial updates
11.2.4. JavaScript API
11.2.5. Reference data
11.3. <rich:column>
11.3.1. Basic usage
11.3.2. Spanning columns
11.3.3. Spanning rows
11.3.4. Reference data
11.4. <rich:columnGroup>
11.4.1. Complex headers
11.4.2. Reference data
11.5. <rich:collapsibleSubTable>
11.5.1. Basic usage
11.5.2. Expanding and collapsing the sub-table
11.5.3. Reference data
11.5.4. <rich:collapsibleSubTableToggler>
11.6. <rich:extendedDataTable>
11.6.1. Basic usage
11.6.2. Table appearance
11.6.3. Extended features
11.6.4. JavaScript API
11.6.5. Reference data
11.7. <rich:dataGrid>
11.7.1. Basic usage
11.7.2. Customizing the grid
11.7.3. Patial updates
11.7.4. Reference data
11.8. <rich:list>
11.8.1. Basic usage
11.8.2. Type of list
11.8.3. Bullet and numeration appearance
11.8.4. Customizing the list
11.8.5. Reference data
11.9. <rich:dataScroller>
11.9.1. Basic usage
11.9.2. Appearance and interactivity
11.9.3. JavaScript API
11.9.4. Reference data
11.10. Table filtering
11.10.1. Basic filtering
11.10.2. External filtering
11.11. Table sorting
11.11.1. External sorting
12. Trees
12.1. <rich:tree>
12.1.1. Basic usage
12.1.2. Appearance
12.1.3. Expanding and collapsing tree nodes
12.1.4. Selecting tree nodes
12.1.5. Identifying nodes with the rowKeyConverter attribute
12.1.6. Event handling
12.1.7. Reference data
12.1.8. <rich:treeNode>
12.2. Tree adaptors
12.2.1. <rich:treeModelAdaptor>
12.2.2. <rich:treeModelRecursiveAdaptor>
13. Menus and toolbars
13.1. <rich:dropDownMenu>
13.1.1. Basic usage
13.1.2. Menu content
13.1.3. Appearance
13.1.4. Expanding and collapsing the menu
13.1.5. Reference data
13.2. Menu sub-components
13.2.1. <rich:menuItem>
13.2.2. <rich:menuGroup>
13.2.3. <rich:menuSeparator>
13.3. <rich:panelMenu>
13.3.1. Basic usage
13.3.2. Interactivity options
13.3.3. Appearance
13.3.4. Submission modes
13.3.5. <rich:panelMenu> server-side events
13.3.6. JavaScript API
13.3.7. Reference data
13.3.8. <rich:panelMenuGroup>
13.3.9. <rich:panelMenuItem>
13.4. <rich:toolbar>
13.4.1. Basic usage
13.4.2. Appearance
13.4.3. Grouping items
13.4.4. Reference data
13.4.5. <rich:toolbarGroup>
14. Output and messages
14.1. <rich:message>
14.1.1. Basic usage
14.1.2. Appearance
14.1.3. Reference data
14.2. <rich:messages>
14.2.1. Basic usage
14.2.2. Appearance
14.2.3. Reference data
14.3. <rich:progressBar>
14.3.1. Basic usage
14.3.2. Customizing the appearance
14.3.3. Using set intervals
14.3.4. Update mode
14.3.5. JavaScript API
14.3.6. Reference data
14.4. <rich:toolTip>
14.4.1. Basic usage
14.4.2. Attaching the tool-tip to another component
14.4.3. Appearance
14.4.4. Update mode
14.4.5. <rich:toolTip> client-side events
14.4.6. JavaScript API
14.4.7. Reference data
15. Drag and drop
15.1. <rich:dragSource>
15.1.1. Basic usage
15.1.2. Dragging an object
15.1.3. Reference data
15.2. <rich:dropTarget>
15.2.1. Basic usage
15.2.2. Handling dropped data
15.2.3. Reference data
15.3. <rich:dragIndicator>
15.3.1. Basic usage
15.3.2. Styling the indicator
15.3.3. Reference data
16. Layout and appearance
16.1. <rich:jQuery>
16.1.1. Basic usage
16.1.2. Defining a selector
16.1.3. Event handlers
16.1.4. Timed queries
16.1.5. Named queries
16.1.6. Dynamic rendering
16.1.7. Reference data
17. Functions
17.1. rich:clientId
17.2. rich:component
17.3. rich:element
17.4. rich:findComponent
17.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 using event listeners.

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> 

JavaServer Faces 2 provides built-in support for bean validation as per the Java Specification Request JSR-303 standard. As such, containers must validate model objects. Validation is performed at different application tiers according to annotation-based constraints. Refer to http://jcp.org/en/jsr/detail?id=303 for further details on the JSR-303 specification.

Example 7.1, “JSR-303 validation annotations” shows an example JSF managed bean. The bean includes JSR-303 annotations for validation. Validation annotations defined in this way are registered on components bound to the bean properties, and validation is triggered in the Process Validation phase.


Requirements

Bean validation in both JavaServer Faces and RichFaces requires the JSR-303 implementation. The implementation is bundled with JEE 6 Application Server.

If using Tomcat or another simple servlet container, add the validation-api Java Archive and a validation provider (such as Hibernate Validator) to your application libraries.

The validation built in to JavaServer Faces 2 occurs on the server side. The <rich:validator> behavior adds client-side validation to a control based on registered server-side validators. It provides this validation without the need to reproduce the server-side annotations. The <rich:validator> behavior triggers all client validator annotations listed in the relevant managed bean.

Use the <rich:message> and <rich:messages> components to display validation messages. The for attribute of the <rich:message> component references the id identifier of the input control being validated.


The <rich:graphValidator> component is used to wrap a set of input components related to one object. The object defined by the <rich:graphValidator> component can then be completely validated. The validation includes all object properties, even those which are not bound to the individual form components. Validation performed in this way allows for cross-field validation in complex forms.

The <rich:graphValidator> element must wrap all the input controls that are required to validate the object. The value attribute names the bean for the validating object.

Example 7.5. Basic usage

The example demonstrates a simple form for changing a password. The two entered passwords must match, so a <rich:graphValidator> component is used for cross-field validation.


<h:form>
   <rich:graphValidator value="#{userBean}">
      <rich:panel header="Change password">
         <rich:messages/>
         <h:panelGrid columns="3">
            <h:outputText value="Enter new password:" />
            <h:inputSecret value="#{userBean.password}" id="pass"/>
            <rich:message for="pass"/>
            <h:outputText value="Confirm the new password:" />
            <h:inputSecret value="#{userBean.confirm}" id="conf"/>
            <rich:message for="conf"/>
         </h:panelGrid>
         <a4j:commandButton value="Store changes"
                            action="#{userBean.storeNewPassword}" />
      </rich:panel>
   </rich:graphValidator>
</h:form>

The input controls validate against the following bean:

@ManagedBean

@RequestScoped
public class UserBean {
   @Size(min = 5, max = 15, message="Wrong size for password")
   private String password;
   @Size(min = 5, max = 15, message="Wrong size for confirmation")
   private String confirm;
   private String status = "";
   
   @AssertTrue(message = "Different passwords entered!")
   public boolean isPasswordsEquals() {
      return password.equals(confirm);
   }
   public void storeNewPassword() {
      FacesContext.getCurrentInstance().addMessage("", new FacesMessage(FacesMessage.SEVERITY_INFO, "Succesfully changed!", "Succesfully changed!"));
   }
   ...
}

When validation occurs, the whole object is validated against the annotation contstraints. The @AssertTrue annotation relies on the isPasswordsEqual() function to check whether the two entered passwords are equal.

If the entered passwords do not match, an error message is displayed:


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="keyup" reRender="out" status="commonstatus" />
                </h:inputText>

                <h:outputText value="Job" />
                <h:inputText id="job" value="#{userBean.job}">
                    <a4j:support event="keyup" 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. Customizing the filter
9.1.4. JavaScript API
9.1.5. Reference data
9.2. <rich:calendar>
9.2.1. Basic usage
9.2.2. Behavior and appearance
9.2.3. Time of day
9.2.4. Localization and formatting
9.2.5. Using a data model
9.2.6. Client-side customization
9.2.7. JavaScript API
9.2.8. Reference data
9.3. <rich:fileUpload>
9.3.1. Basic usage
9.3.2. Upload settings
9.3.3. Interactivity options
9.3.4. <rich:fileUpload> client-side events
9.3.5. Reference data
9.4. <rich:inplaceInput>
9.4.1. Basic usage
9.4.2. Interactivity options
9.4.3. JavaScript API
9.4.4. Reference data
9.5. <rich:inplaceSelect>
9.5.1. Basic usage
9.5.2. Interactivity options
9.5.3. JavaScript API
9.5.4. Reference data
9.6. <rich:inputNumberSlider>
9.6.1. Basic usage
9.6.2. Interactivity options
9.6.3. JavaScript API
9.6.4. Reference data
9.7. <rich:inputNumberSpinner>
9.7.1. Basic usage
9.7.2. Interactivity options
9.7.3. JavaScript API
9.7.4. Reference data
9.8. <rich:select>
9.8.1. Basic usage
9.8.2. Advanced options
9.8.3. Using manual input
9.8.4. JavaScript API
9.8.5. 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:accordion>
10.2.1. Basic usage
10.2.2. Switching panels
10.2.3. <rich:accordion> client-side events
10.2.4. <rich:accordion> server-side events
10.2.5. JavaScript API
10.2.6. Reference data
10.2.7. <rich:accordionItem>
10.3. <rich:collapsiblePanel>
10.3.1. Basic usage
10.3.2. Expanding and collapsing the panel
10.3.3. Appearance
10.3.4. <rich:collapsiblePanel> server-side events
10.3.5. JavaScript API
10.3.6. 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. JavaScript API
10.4.8. Reference data
10.5. <rich:tabPanel>
10.5.1. Switching panels
10.5.2. <rich:tabPanel> client-side events
10.5.3. <rich:tabPanel> server-side events
10.5.4. JavaScript API
10.5.5. Reference data
10.5.6. <rich:tab>
10.6. <rich:togglePanel>
10.6.1. Basic usage
10.6.2. Toggling between components
10.6.3. JavaScript API
10.6.4. Reference data
10.6.5. <rich:toggleControl>
10.6.6. <rich:togglePanelItem>
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:dataTable>
11.2.1. Basic usage
11.2.2. Customizing the table
11.2.3. Partial updates
11.2.4. JavaScript API
11.2.5. Reference data
11.3. <rich:column>
11.3.1. Basic usage
11.3.2. Spanning columns
11.3.3. Spanning rows
11.3.4. Reference data
11.4. <rich:columnGroup>
11.4.1. Complex headers
11.4.2. Reference data
11.5. <rich:collapsibleSubTable>
11.5.1. Basic usage
11.5.2. Expanding and collapsing the sub-table
11.5.3. Reference data
11.5.4. <rich:collapsibleSubTableToggler>
11.6. <rich:extendedDataTable>
11.6.1. Basic usage
11.6.2. Table appearance
11.6.3. Extended features
11.6.4. JavaScript API
11.6.5. Reference data
11.7. <rich:dataGrid>
11.7.1. Basic usage
11.7.2. Customizing the grid
11.7.3. Patial updates
11.7.4. Reference data
11.8. <rich:list>
11.8.1. Basic usage
11.8.2. Type of list
11.8.3. Bullet and numeration appearance
11.8.4. Customizing the list
11.8.5. Reference data
11.9. <rich:dataScroller>
11.9.1. Basic usage
11.9.2. Appearance and interactivity
11.9.3. JavaScript API
11.9.4. Reference data
11.10. Table filtering
11.10.1. Basic filtering
11.10.2. External filtering
11.11. Table sorting
11.11.1. External sorting
12. Trees
12.1. <rich:tree>
12.1.1. Basic usage
12.1.2. Appearance
12.1.3. Expanding and collapsing tree nodes
12.1.4. Selecting tree nodes
12.1.5. Identifying nodes with the rowKeyConverter attribute
12.1.6. Event handling
12.1.7. Reference data
12.1.8. <rich:treeNode>
12.2. Tree adaptors
12.2.1. <rich:treeModelAdaptor>
12.2.2. <rich:treeModelRecursiveAdaptor>
13. Menus and toolbars
13.1. <rich:dropDownMenu>
13.1.1. Basic usage
13.1.2. Menu content
13.1.3. Appearance
13.1.4. Expanding and collapsing the menu
13.1.5. Reference data
13.2. Menu sub-components
13.2.1. <rich:menuItem>
13.2.2. <rich:menuGroup>
13.2.3. <rich:menuSeparator>
13.3. <rich:panelMenu>
13.3.1. Basic usage
13.3.2. Interactivity options
13.3.3. Appearance
13.3.4. Submission modes
13.3.5. <rich:panelMenu> server-side events
13.3.6. JavaScript API
13.3.7. Reference data
13.3.8. <rich:panelMenuGroup>
13.3.9. <rich:panelMenuItem>
13.4. <rich:toolbar>
13.4.1. Basic usage
13.4.2. Appearance
13.4.3. Grouping items
13.4.4. Reference data
13.4.5. <rich:toolbarGroup>
14. Output and messages
14.1. <rich:message>
14.1.1. Basic usage
14.1.2. Appearance
14.1.3. Reference data
14.2. <rich:messages>
14.2.1. Basic usage
14.2.2. Appearance
14.2.3. Reference data
14.3. <rich:progressBar>
14.3.1. Basic usage
14.3.2. Customizing the appearance
14.3.3. Using set intervals
14.3.4. Update mode
14.3.5. JavaScript API
14.3.6. Reference data
14.4. <rich:toolTip>
14.4.1. Basic usage
14.4.2. Attaching the tool-tip to another component
14.4.3. Appearance
14.4.4. Update mode
14.4.5. <rich:toolTip> client-side events
14.4.6. JavaScript API
14.4.7. Reference data
15. Drag and drop
15.1. <rich:dragSource>
15.1.1. Basic usage
15.1.2. Dragging an object
15.1.3. Reference data
15.2. <rich:dropTarget>
15.2.1. Basic usage
15.2.2. Handling dropped data
15.2.3. Reference data
15.3. <rich:dragIndicator>
15.3.1. Basic usage
15.3.2. Styling the indicator
15.3.3. Reference data
16. Layout and appearance
16.1. <rich:jQuery>
16.1.1. Basic usage
16.1.2. Defining a selector
16.1.3. Event handlers
16.1.4. Timed queries
16.1.5. Named queries
16.1.6. Dynamic rendering
16.1.7. Reference data
17. Functions
17.1. rich:clientId
17.2. rich:component
17.3. rich:element
17.4. rich:findComponent
17.5. rich:isUserInRole

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.

Figure 9.1. <rich:autocomplete>


The <rich:autocomplete> component uses the JavaScript startsWith() method to create the list of suggestions. The filtering is performed on the client side. Alternatively, use the clientFilter attribute to specify a custom filtering function. The custom function must accept two parameters: the subString parameter is the filtering value as typed into the text box by the user, and the value parameter is an item in the list of suggestions against which the subString must be checked. Each item is iterated through and passed to the function as the value parameter. The custom function must return a boolean value indicating whether the passed item meets the conditions of the filter, and the suggestion list is constructed from successful items.


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>


Instead of using a data model, the <rich:calendar> component can be customized on the client-side using JavaScript. Use the dayClassFunction attribute to reference the function that determines the CSS style class for each day cell. Use the dayDisableFunction to reference the function that enables or disables a day cell. Example 9.4, “Client-side customization” demonstrates how client-side customization can be used to style different days in a calendar.


The <rich:fileUpload> component allows the user to upload files to a server. It features multiple uploads, progress bars, restrictions on file types, and restrictions on sizes to be uploaded.

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.3. <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.4. <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.5. <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. The <rich:select> component functions similarly to the JavaServer Faces <h:selectOneMenu> component.

Figure 9.6. <rich:select>


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.3. 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.4. <rich:collapsiblePanel>


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

Figure 10.6. 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: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.

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.6.5, “<rich:toggleControl>” and Section 10.6, “<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.

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.6, “<rich:togglePanel>” and Section 10.6.6, “<rich:togglePanelItem>” for details on how to use the components together.

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: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.10, “Table filtering” and Section 11.11, “Table sorting”.

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.6, “Complex headers using column groups” and the resulting Figure 11.5, “Complex headers using column groups” demonstrate how complex headers can be achieved.

Example 11.6. Complex headers using column groups


The <rich:collapsibleSubTable> component acts as a child element to a <rich:dataTable> component. It allows sections of a table to be grouped into collapsible sections. The <rich:collapsibleSubTable> component works with the <rich:collapsibleSubTableToggler> component, which allows the user to expand and collapse the sub tables.

The <rich:collapsibleSubTable> component requires the same basic attributes as the <rich:dataTable> component. The value attribute points to the collection, and the var attribute specifies a variable to use when iterating through the collection.

In addition, the <rich:collapsibleSubTable> component typically needs a corresponding <rich:collapsibleSubTableToggler> component to allow expanding and collapsing. Declare the id identifier on the <rich:collapsibleSubTable> element so that the <rich:collapsibleSubTableToggler> component can reference it. Refer to Section 11.5.4, “<rich:collapsibleSubTableToggler>” for details on the <rich:collapsibleSubTableToggler> component.

Example 11.7. Basic usage


<rich:dataTable value="#{carsBean.inventoryVendorLists}" var="list">
   <f:facet name="header">
      <rich:columnGroup>
         <rich:column colspan="6">
            <h:outputText value="Cars marketplace" />
         </rich:column>
         <rich:column breakRowBefore="true">
            <h:outputText value="Model" />
         </rich:column>
         <rich:column>
            <h:outputText value="Price" />
         </rich:column>
         <rich:column>
            <h:outputText value="Mileage" />
         </rich:column>
         <rich:column>
            <h:outputText value="VIN Code" />
         </rich:column>
         <rich:column>
            <h:outputText value="Items stock" />
         </rich:column>
         <rich:column>
            <h:outputText value="Days Live" />
         </rich:column>
      </rich:columnGroup>
   </f:facet>
   <rich:column colspan="6">
      <rich:collapsibleSubTableToggler for="sbtbl" />
      <h:outputText value="#{list.vendor}" />
   </rich:column>
   <rich:collapsibleSubTable value="#{list.vendorItems}" var="item" id="sbtbl"
      expandMode="client">
      <rich:column>
         <h:outputText value="#{item.model}" />
      </rich:column>
      <rich:column>
         <h:outputText value="#{item.price}" />
      </rich:column>
      <rich:column>
         <h:outputText value="#{item.mileage}" />
      </rich:column>
      <rich:column>
         <h:outputText value="#{item.vin}" />
      </rich:column>
      <rich:column>
         <h:outputText value="#{item.stock}" />
      </rich:column>
      <rich:column>
         <h:outputText value="#{item.daysLive}" />
      </rich:column>
      <f:facet name="footer">
         <h:outputText value="Total of #{list.vendor} Cars: #{list.count}" />
      </f:facet>
   </rich:collapsibleSubTable>
</rich:dataTable>

The resulting tables contains multiple sub-tables, grouping the list of cars by vendor. Each sub-table can be expanded or collapsed using the toggle with the vendor's name. The screenshot shows all sub-tables collapsed except for the sub-table for Ford cars.


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 main attributes not included in the <rich:dataTable> component:

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

Example 11.8. <rich:extendedDataTable> example

This example <rich:extendedDataTable> component demonstrates horizontal and vertical scrolling and frozen columns. Each feature is detailed in this section.


<rich:extendedDataTable value="#{carsBean.allInventoryItems}"
                        var="car" id="table" frozenColumns="2"
                        style="height:300px; width:500px;" selectionMode="none">
   <f:facet name="header">
      <h:outputText value="Cars marketplace" />
   </f:facet>
   <rich:column>
      <f:facet name="header">
         <h:outputText value="vendor" />
      </f:facet>
      <h:outputText value="#{car.vendor}" />
   </rich:column>
   <rich:column>
      <f:facet name="header">
         <h:outputText value="Model" />
      </f:facet>
      <h:outputText value="#{car.model}" />
   </rich:column>
   <rich:column>
      <f:facet name="header">
         <h:outputText value="Price" />
      </f:facet>
      <h:outputText value="#{car.price}" />
   </rich:column>
   <rich:column>
      <f:facet name="header">
         <h:outputText value="Mileage" />
      </f:facet>
      <h:outputText value="#{car.mileage}" />
   </rich:column>
   <rich:column>
      <f:facet name="header">
         <h:outputText value="VIN Code" />
      </f:facet>
      <h:outputText value="#{car.vin}" />
   </rich:column>
   <rich:column>
      <f:facet name="header">
         <h:outputText value="Items stock" />
      </f:facet>
      <h:outputText value="#{car.stock}" />
   </rich:column>
   <rich:column>
      <f:facet name="header">
         <h:outputText value="Days Live" />
      </f:facet>
      <h:outputText value="#{car.daysLive}" />
   </rich:column>
</rich:extendedDataTable>

The example table shown in Example 11.8, “<rich:extendedDataTable> example” features both horizontal and vertical scrolling. Scrolling occurs automatically when the contents of the table exceed the dimensions specified with the height and width attributes. Headers and footers remain in place and visible when the table is scrolled.

Large tables can use Ajax "lazy" loading to cache data on the client during scrolling. Use the clientRows attribute to specify the number of rows to load. The specified number of rows are loaded on the initial rendering and with every vertical scroll. If the clientRows attribute is not specified, all the rows are loaded on the client without the use of Ajax.

In addition to Ajax scrolling, the <rich:extendedDataTable> component can also be used with the <rich:dataScroller> component in the same way as a regular <rich:dataTable> component. Refer to Section 11.9, “<rich:dataScroller>” for full details on using the <rich:dataScroller> component.

The example table shown in Example 11.8, “<rich:extendedDataTable> example” has the first two columns frozen so that they remain visible if the user scrolls horizontally through the table. Note that the horizontal scrollbar does not encompass these frozen columns. To freeze columns, use the frozenColumns attribute to specify the number of columns on the left-hand side of the table to freeze.

Row selection is determined by the selectionMode attribute. Setting the attribute to none allows for no row selection capability. The example table shown in Example 11.8, “<rich:extendedDataTable> example” does not allow row selection.

Setting the selectionMode attribute to single allows the user to select a single row at a time using the mouse. With the selectionMode attribute set to multi, the user can select multiple rows. Holding down the Ctrl key while clicking selects additional rows with each click. Holding down the Shift key while clicking selects all the rows in a range.

The selection attribute points to a collection of objects. It holds the rowKey identifiers to track which rows are selected. Example 11.9, “Selecting multiple rows” shows how to implement multiple row selection in the same table from Example 11.8, “<rich:extendedDataTable> example”.

Example 11.9. Selecting multiple rows


<rich:extendedDataTable value="#{extTableSelectionBean.inventoryItems}" 
                        var="car" selection="#{extTableSelectionBean.selection}"
                        id="table" frozenColumns="2" 
                        style="height:300px; width:500px;" selectionMode="multi">
   ...

The accompanying ExtSelectionBean bean handles which rows are selected. The rows are identified by their rowKey identifiers.

package org.richfaces.demo.tables;


import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.faces.event.AjaxBehaviorEvent;
import org.richfaces.component.UIExtendedDataTable;
import org.richfaces.demo.tables.model.cars.InventoryItem;
@ManagedBean
@SessionScoped
public class ExtTableSelectionBean implements Serializable{
   private Collection<Object> selection;
   @ManagedProperty(value = "#{carsBean.allInventoryItems}")
   private List<InventoryItem> inventoryItems;
   private List<InventoryItem> selectionItems = new ArrayList<InventoryItem>();
   public void selectionListener(AjaxBehaviorEvent event){
      UIExtendedDataTable dataTable = (UIExtendedDataTable)event.getComponent();
      Object originalKey = dataTable.getRowKey();
      selectionItems.clear();
      for (Object selectionKey: selection) {
         dataTable.setRowKey(selectionKey);
         if (dataTable.isRowAvailable()){
            selectionItems.add((InventoryItem)dataTable.getRowData());
         }
      }
      dataTable.setRowKey(originalKey);
   }
   public Collection<Object> getSelection() {
      return selection;
   }
   public void setSelection(Collection<Object> selection) {
      this.selection = selection;
   }
   public List<InventoryItem> getInventoryItems() {
      return inventoryItems;
   }
   public void setInventoryItems(List<InventoryItem> inventoryItems) {
      this.inventoryItems = inventoryItems;
   }
   public List<InventoryItem> getSelectionItems() {
      return selectionItems;
   }
   public void setSelectionItems(List<InventoryItem> selectionItems) {
      this.selectionItems = selectionItems;
   }
}

Columns in a <rich:extendedDataTable> component can be rearranged by the user by dragging each column to a different position. A graphical representation of the column is displayed during dragging. Figure 11.6, “Dragging columns” illustrates the Price column being dragged to a new location. The small blue arrow indicates where the column will be moved to if it is dropped in the current position. Figure 11.7, “Rearranged columns” shows the result of dragging the Price column.

Figure 11.6. Dragging columns


Figure 11.7. Rearranged columns


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.8. The <rich:dataGrid> component


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

The <rich:dataScroller> component is used for navigating through multiple pages of tables or grids.

Figure 11.14. The <rich:dataScroller> component


The page attribute is a value-binding attribute used to define and save the current page number.

The <rich:dataScroller> component provides a range of controllers for scrolling through tables and grids:

The pageIndexVar and pagesVar attributes are request-scope variables for the current page and the total number of pages. Use these attributes with the pages facet to provide information about the pages of the table, as shown in Example 11.14, “pages facet”.


To add optional separators between controls, define the separators with the controlsSeparator facet.

Tables entries can be filtered by the user through either the basic method built in to the <rich:column> component, or by defining external filters. Refer to Section 11.3, “<rich:column>” for details on using the <rich:column> component in tables.

The built-in filtering abilities of the <rich:column> component allow the user to enter text as a filtering value. The table displays only those entries that begin with the filter value.

Set the filterValue attribute to point to the value used to filter the column. This can be either an initial filtering value on the page, or a value binding on the server. The filterValue value is then used with the JavaScript startsWith() method to filter the column entries based on the data specified with the filterBy attribute. Expressions in the filterBy attribute must refer to the variable declared in the table's var attribute, which is used to fill the contents of the table.

The filter is processed and the table is rendered when the onblur event occurs for the column. This can be changed by defining a different event with the filterEvent attribute. For example, to implement live updating such that the filter refreshes after every keystroke, set filterEvent="keyup".


If you require more advanced filtering using custom functions or expressions, use the external filtering properties of the <rich:column> component.

Use the filterExpression attribute to define an expression that can be evaluated as a boolean value. The expression checks if each table entry satisfies the filtering condition when the table is rendered.

Use the filterMethod attribute to define a method binding. The method needs to accept an object as a parameter and return a boolean value. Similar to the filterExpression attribute, the table is rendered only with those entries that satisfy the filtering condition. By defining a custom filtering method, you can implement complex business logic to filter a table.

Example 11.16. External filtering


<rich:dataTable value="#{capitalsBean.capitals}" var="cap" id="table">
   <f:facet name="header">
      <rich:column>
         <h:outputText value="State Name">
      </rich:column>
      <rich:column>
         <h:outputText value="State Time Zone">
      </rich:column>
   </f:facet>
   <rich:column filterMethod="#{filteringBean.filterStates}">
        <f:facet name="header">
            <h:inputText value="#{filteringBean.filterValue}" id="input">
                <a4j:ajax event="keyup" render="table"
                              ignoreDupResponses="true" requestDelay="700"/>
            </h:inputText>
        </f:facet>
      <h:outputText value="#{cap.state}"/>
   </rich:column> 
   <rich:column filterExpression=
      "#{fn:containsIgnoreCase(cap.timeZone, filteringBean.filterZone)}">
        <f:facet name="header">
            <h:selectOneMenu value="#{filteringBean.filterZone}">
                <f:selectItems value="#{filteringBean.filterZones}" />
                <a4j:ajax event="change" render="table" />
            </h:selectOneMenu>
        </f:facet>
      <h:outputText value="#{cap.timeZone}"/> 
   </rich:column>
</rich:dataTable>

The example uses a filter expression on the first column and a filter method on the second column.


Tables entries can be sorted by defining external sorting algorithms. Refer to Section 11.3, “<rich:column>” for details on using the <rich:column> component in tables.

Sorting non-English tables

To sort a table whose contents are not in English, add the org.richfaces.datatableUsesViewLocale context parameter to the project's web.xml settings file. Set the value of the context parameter to true.

Bind the sortOrder attribute to bean properties to manage the sorting order externally. The bean must handle all the sorting algorithms. Example 11.17, “External sorting” demonstrates table sorting using an external control.

Example 11.17. External sorting


<rich:dataTable value="#{dataTableScrollerBean.allCars}"
                var="category" rows="20" id="table" reRender="ds2"
                sortPriority="#{sortingBean.prioritList}">
   <rich:column id="make" sortBy="#{category.make}"
                sortOrder="#{sortingBean.makeDirection}">
      <f:facet name="header">
         <h:outputText styleClass="headerText" value="Make" />
      </f:facet>
      <h:outputText value="#{category.make}" />
   </rich:column>
   <rich:column id="model" sortBy="#{category.model}"
                sortOrder="#{sortingBean.modelDirection}">
      <f:facet name="header">
         <h:outputText styleClass="headerText" value="Model" />
      </f:facet>
      <h:outputText value="#{category.model}" />
   </rich:column>
   <rich:column id="price" sortBy="#{category.price}"
                sortOrder="#{sortingBean.priceDirection}">
      <f:facet name="header">
         <h:outputText styleClass="headerText" value="Price" />
      </f:facet>
      <h:outputText value="#{category.price}" />
   </rich:column>
   <rich:column id="mileage" sortBy="#{category.mileage}"
                sortOrder="#{sortingBean.mileageDirection}">
      <f:facet name="header">
         <h:outputText styleClass="headerText" value="Mileage" />
      </f:facet>
      <h:outputText value="#{category.mileage}" />
   </rich:column>
</rich:dataTable>

The example uses an external control to manage the table's sorting.


When using the sortMode="multiple" configuration, set the priority by which columns are sorted with the sortPriorities attribute.

Use the sortExpression attribute to define a bean property to use for sorting the column. The expression checks each table entry against the sorting expression during rendering.

Read this chapter for details on components that use tree structures.

The <rich:tree> component provides a hierarchical tree control. Each <rich:tree> component typically consists of <rich:treeNode> child components. The appearance and behavior of the tree and its nodes can be fully customized.

The <rich:tree> component requires the value attribute to point to the data model for populating the tree. The data model must be either an org.richfaces.model.TreeNode interface, an org.richfaces.model.TreeDataModel interface, or a javax.swing.tree.TreeNode interface. The var attribute declares the variable used for iterating through the data model, so that child <rich:treeNode> components can reference each iteration.

Ideally, the <rich:tree> component needs one or more <rich:treeNode> components to work with the data model. However if no <rich:treeNode> components are provided the tree creates default nodes instead.


Different nodes in the tree can have different appearances, such as node icons, depending on the type of data the node contains. Use the nodeType attribute to differentiate the types of nodes; the node is then rendered according to the <rich:treeNode> component with the corresponding type attribute. Example 12.2, “nodeType attribute” shows a <rich:tree> component with three different child <rich:treeNode> components defined to represent three different node appearances. Refer to Section 12.1.8.2, “Appearance” for details on customizing the appearance of <rich:treeNode> components.


If the nodeType attribute returns null, the node is rendered as a "typeless" (or default) node. The typeless node is the first child <rich:treeNode> component with a valid rendered attribute, but without a defined type attribute.

If the nodeType attribute is not included and there are no child <rich:treeNode> components, the tree constructs a default node itself.

Icons for different nodes and node states can be defined for the whole tree using the following attributes:

iconLeaf

The iconLeaf attribute points to the icon to use for any node that does not contain any child nodes.

iconExpanded and iconCollapsed

The iconExpanded and iconCollapsed attributes point to the icons to use for expanded and collapsed nodes respectively. If these attributes are defined, the icon attribute is not used.

The <rich:treeNode> component is a child component of the <rich:tree> component. It represents nodes in the parent tree. The appearance and functionality of each tree node can be customized.

Refer to Section 12.1.2, “Appearance” for the <rich:tree> component for details and examples on styling nodes and icons. Icon styling for individual <rich:treeNode> components uses the same attributes as the parent <rich:tree> component: iconLeaf, iconExpanded, and iconCollapsed. Icon-related attributes specified for child <rich:treeNode> components overwrite any global icon attributes of the parent <rich:tree> component.

Use the rendered attribute to determine whether the node should actually be rendered in the tree or not. Using the rendered attribute in combination with the <rich:treeNode> type attribute can allow further style differentiation between node content, as shown in Example 12.3, “rendered attribute”.


Use a tree adaptor to populate a tree model declaratively from a non-hierarchical model, such as a list or a map.

The <rich:treeModelAdaptor> component takes an object which implements the Map or Iterable interfaces. It adds all the object entries to the parent node as child nodes.

<rich:treeModelAdaptor> components can further be nested in other <rich:treeModelAdaptor> components to subsequently populate lower levels of the tree.

To access the current element at each iteration, use the var attribute of either the parent <rich:tree> component or the <rich:treeModelAdaptor> component itself. Example 12.4, “Nested <rich:treeModelAdaptor> components” demonstrates a series of nested <rich:treeModelAdaptor> components, each using the parent's var attribute to reference the current element.


Each <rich:treeModelAdaptor> component is mapped to a list of objects. During the iteration, the corresponding object properties are used to define the node labels and actions, and are in turn used for iterating through nested lists.

Adaptors that use Map interfaces or models with non-string keys require a row key converter in order to correctly identify nodes. Refer to Section 12.1.5, “Identifying nodes with the rowKeyConverter attribute” for details on the use of the rowKeyConverter attribute.

Adaptors that use Iterable interfaces have simple integer row keys. A default converter is provided and does not need to be referenced explicitly.

The <rich:treeModelRecursiveAdaptor> component iterates through recursive collections in order to populate a tree with hierarchical nodes, such as for a file system with multiple levels of directories and files.

The <rich:treeModelRecursiveAdaptor> component is an extension of the <rich:treeModelAdaptor> component. As such, the <rich:treeModelRecursiveAdaptor> component uses all of the same attributes. Refer to Section 12.2.1, “<rich:treeModelAdaptor>” for details on the <rich:treeModelAdaptor> component.

In addition, the <rich:treeModelRecursiveAdaptor> component requires the root attribute. The root attribute defines the collection to use at the top of the recursion. For subsequent levels, the node attribute is used for the collection.

Example 12.5, “Basic usage” demonstrates how the <rich:treeModelRecursiveAdaptor> component can be used in conjunction with the <rich:treeModelAdaptor> component to recursively iterate through a file system and create a tree of directories and files.

Example 12.5. Basic usage


<rich:tree var="item">
   <rich:treeModelRecursiveAdaptor roots="#{fileSystemBean.sourceRoots}" nodes="#{item.directories}" >
      <rich:treeNode>
         #{item.shortPath}
      </rich:treeNode>
      <rich:treeModelAdaptor nodes="#{item.files}">
         <rich:treeNode>#{item}</rich:treeNode>
      </rich:treeModelAdaptor>
   </rich:treeModelRecursiveAdaptor>
</rich:tree>

The <rich:treeModelRecursiveAdaptor> component references the FileSystemBean class as the source for the data.

@ManagedBean

@RequestScoped
public class FileSystemBean {
   private static final String SRC_PATH = "/WEB-INF";
   private List<FileSystemNode> srcRoots;
   public synchronized List<FileSystemNode> getSourceRoots() {
      if (srcRoots == null) {
         srcRoots = new FileSystemNode(SRC_PATH).getDirectories();
      }
      return srcRoots;
   }
}

The FileSystemBean class in turn uses the FileSystemNode class to recursively iterate through the collection.

public class FileSystemNode {

   ...
   public synchronized List<FileSystemNode> getDirectories() {
      if (directories == null) {
         directories = Lists.newArrayList();
         Iterables.addAll(directories, transform(filter(getResourcePaths(), containsPattern("/$")), FACTORY));
      }
      return directories;
   }
   public synchronized List<String> getFiles() {
      if (files == null) {
         files = new ArrayList<String>();
         Iterables.addAll(files, transform(filter(getResourcePaths(), not(containsPattern("/$"))), TO_SHORT_PATH));
      }
      return files;
   }
   private Iterable<String> getResourcePaths() {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ExternalContext externalContext = facesContext.getExternalContext();
        Set<String> resourcePaths = externalContext.getResourcePaths(this.path);
        
      if (resourcePaths == null) {
         resourcePaths = Collections.emptySet();
      }
      return resourcePaths;
   }   
   ...
}

The getDirectories() function is used recursively until the object has the collection of children. The model adaptor calls the getFiles() function at each level in order to add the file nodes.

The resulting tree hierarchically lists the directories and files in the collection.


Adaptors that use Map interfaces or models with non-string keys require a row key converter in order to correctly identify nodes. Refer to Section 12.1.5, “Identifying nodes with the rowKeyConverter attribute” for details on the use of the rowKeyConverter attribute.

Adaptors that use Iterable interfaces have simple integer row keys. A default converter is provided and does not need to be referenced explicitly.

Read this chapter for details on menu and toolbar components.

The <rich:dropDownMenu> component is used for creating a drop-down, hierarchical menu. It can be used with the <rich:toolbar> component to create menus in an application's toolbar.

Figure 13.1. <rich:dropDownMenu>


The <rich:menuItem>, <rich:menuGroup>, and <rich:menuSeparator> components are used to construct menus for the <rich:dropDownMenu> component. Refer to Section 13.1, “<rich:dropDownMenu>” for more details on the <rich:dropDownMenu> component.

The <rich:menuItem> component represents a single item in a menu control. The <rich:menuItem> component can be also be used as a seperate component without a parent menu component, such as on a toolbar.

The <rich:panelMenu> component is used in conjunction with <rich:panelMenuItem> and <rich:panelMenuGroup> to create an expanding, hierarchical menu. The <rich:panelMenu> component's appearance can be highly customized, and the hierarchy can stretch to any number of sub-levels.


Icons for the panel menu can be chosen from a set of standard icons. Icons can be set for the top panel menu, child panel menus, and child item. There are three different menu states that the icon represents, as well as icons for both the left and right side of the item title.

Example 13.2, “richpanelMenu” demonstrates the use of icon declaration at the panel menu level. The standard icons are shown in Figure 13.2, “<Standard icons>”.


Alternatively, point the icon attributes to the paths of image files. The image files are then used as icons.

Any icons specified by child <rich:panelMenuGroup> and <rich:panelMenuItem> components overwrite the relevant icons declared with the parent <rich:panelMenu> component.

The <rich:panelMenuGroup> component defines a group of <rich:panelMenuItem> components inside a <rich:panelMenu>.

Icons for the menu group are inherited from the parent <rich:panelMenu> component. Refer to Section 13.3.3, “Appearance” for details on icon attributes and facets. Alternatively, the menu group's icons can be re-defined at the <rich:panelMenuGroup> component level, and these settings will be used instead of the parent component's settings.

The <rich:panelMenuItem> component represents a single item inside a <rich:panelMenuGroup> component, which is in turn part of a <rich:panelMenu> component.

Icons for the menu item are inherited from the parent <rich:panelMenu> or <rich:panelMenuGroup> component. Refer to Section 13.3.3, “Appearance” for details on icon attributes and facets. Alternatively, the menu item's icons can be re-defined at the <rich:panelMenuItem> component level, and these settings will be used instead of the parent component's settings.

The <rich:toolbar> component is a horizontal toolbar. Any JavaServer Faces (JSF) component can be added to the toolbar.

Figure 13.3. <rich:toolbar>


Set the width and height of the toolbar using the common width and height attributes.

Items on the toolbar can be separated by a graphical item separator. Use the itemSeparator attribute to specify one of the standard separator styles:

Alternatively, use the itemSeparator attribute to specify a URL to an image. The image is then used as an item separator. The appearance of the item separator can be additionally customized by using the itemSeparator facet.

The <rich:toolbarGroup> component is a child component of the <rich:toolbar> component. The <rich:toolbarGroup> component is used to group a number of items together on a toolbar.

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

The <rich:message> component renders a single message relating to another specific component. The message consists of two parts, both of which are optional: the marker icon and the textual label. The appearance of the message can be customized, and tool-tips can be used for further information about the message.

Figure 14.1. rich:message component


The <rich:messages> components works similarly to the <rich:message> component, but can display validation messages for a group of components instead of just a single component. Refer to Section 14.1, “<rich:message>” for details on the <rich:message> component.

Figure 14.2. rich:messages component


The <rich:messages> component displays error messages for each validating component in the same container. The passedLabel attribute contains a message to display when there are no errors; that is, when validation for all components passes successfully. The layout attribute defines how the messages are presented: either using list for a list layout, or table for a tabular layout.

All messages use the same state icons, specified by using facets in the same way as for the <rich:message> component:

Example 14.2. rich:messages example


<h:form>
    <rich:messages passedLabel="Data validated." layout="list">
        <f:facet name="header">
            <h:outputText value="Entered Data Status:"></h:outputText>
        </f:facet>
        <f:facet name="passedMarker">
            <h:graphicImage  value="/images/ajax/passed.gif" /> 
        </f:facet>
        <f:facet name="errorMarker">
            <h:graphicImage value="/images/ajax/error.gif" />   
        </f:facet>
    </rich:messages>

    <h:panelGrid columns="2">
        <h:outputText value="Name:" />
        <h:inputText label="Name" id="name" required="true" value="#{userBean.name}">
            <f:validateLength minimum="3"  />
        </h:inputText>
        <h:outputText value="Job:" />
        <h:inputText label="Job" id="job" required="true" value="#{userBean.job}">
            <f:validateLength minimum="3" maximum="50"  />
        </h:inputText>
        <h:outputText value="Address:" />
        <h:inputText label="Address" id="address" required="true" value="#{userBean.address}">
            <f:validateLength minimum="10" />
        </h:inputText>
        <h:outputText value="Zip:" />
        <h:inputText label="Zip" id="zip" required="true" value="#{userBean.zip}">
            <f:validateLength minimum="4" maximum="9"  />
        </h:inputText>
        <f:facet name="footer">
            <a4j:commandButton value="Validate" />
        </f:facet> 
    </h:panelGrid>
</h:form>

    

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 14.3. <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 14.7, “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 14.4. <rich:toolTip>


Read this chapter for details on adding drag and drop support to controls.

The <rich:dragSource> component can be added to a component to indicate it is capable of being dragged by the user. The dragged item can then be dropped into a compatible drop area, designated using the <rich:dropTarget> component.

The <rich:dropTarget> component can be added to a component so that the component can accept dragged items. The dragged items must support the <rich:dragSource> component, and be of a compatible drop type.

The <rich:dragIndicator> component defines a graphical element to display under the mouse cursor during a drag-and-drop operation.

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 16.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.