JBoss.orgCommunity Documentation

Chapter 5. Advanced features

5.1. JSF2 integration
5.2. Performance optimization
5.3. Traffic control and queues
5.4. Validation
5.5. Script and style loading
5.5.1. org.richfaces.LoadScriptStrategy
5.5.2. org.richfaces.LoadStyleStrategy
5.6. Error handling
5.6.1. Handling request errors
5.6.2. Handling session expiration errors
5.7. Managing states
5.8. User roles

Documentation in development

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

Read this chapter for details on some of the advanced features and configuration possibilities for the RichFaces framework.

JavaServer Faces (JSF) is the Java-based web application framework upon which the RichFaces framework has been built. RichFaces is now integrated with JSF2, which features several improvements to the framework.

The RichFaces framework includes several components designed to improve application performance. Script and style management can be optimized with resource-loading components such as <a4j:loadBundle>, <a4j:loadScript>, and <a4j:loadStyle>.

For further details on optimizing the performance of RichFaces applications, refer to the Resources and Processing management chapters in the Component Reference Guide.

The RichFaces framework allows for queues to manage traffic from Ajax requests, events, and page updates. Controlling the message processing with a queue can make applications more efficient and avoid problems with data corruption. Basic queuing is available with all RichFaces components, and the <a4j:queue> component adds advanced queuing to standard JSF components.

For further details on RichFaces queue management, refer to the queuing details in the Common Ajax attributes chapter and the Processing management chapter in the Component Reference Guide.

The RichFaces framework features several validation components. These components can validate Ajax actions, or validate data against model-based constraints defined using Hibernate Validator.

For further details on RichFaces validation components, refer to the Validation chapter of the Component Reference Guide.

Scripts and styles are normally loaded into a RichFaces application on demand. The default loading strategy can be altered to suit certain applications by specifying the strategy in the web.xml file.

RichFaces allows standard handlers to be defined for processing different application exceptions. Custom JavaScript can be executed when these exceptions occur.

To define handlers for application exceptions, add the following code to your web.xml file:


<context-param>
    <param-name>org.ajax4jsf.handleViewExpiredOnClient</param-name>
    <param-value>true</param-value>
</context-param>

JavaServer Faces (JSF) has an advanced navigation mechanism that allows you to define navigation from one view to another. Navigation typically happens in a web application when a user moves from one page to another, but there is no switch mechanism between certain logical states in the same view. The RichFaces State API allows sets of states to be defined for the views, as well as any properties associated with these states.

Actually States is a map where the entry key is a name of the State and the value is a State map. Particular State map has entries with some names as keys and any objects as values that are used after the state activation. Thus, in the State map you could define any values, method bindings, or just some simple state variables (constants) which have different values for every State.

To check whether the logged-in user belongs to a certain user role, use the rich:isUserInRole(Object) function in RichFaces. The example demonstrates the function's use to render controls only for users with administrator privileges.