Wednesday 18 May 2011

Richfaces 4 Why and How!!!



It has a latest stable release of Richfaces 4.0.0.Final. Though few features like hotkey and contextmenu not available in this release (planned to release in the release 4.1), it would be better to move the projects which uses Richfaces 3.3.3 and JSF 2 to use Richfaces 4.0 now!

Why Richfaces 4?
First question in mind is “what’s new in it”! Here are the features:
  • Richfaces 4 allows users to take full advantage of all the enhancements in JSF 2.
  • A full set of AJAX enabled components in two libraries
    1. a4j: page centric AJAX controls (a4j:ajax extending the base JSF 2.0 f:ajax tag)
    2. rich: self contained, ready to use components
  • Client-side validation, expanding JSR 303 Bean Validation all the way to the browser.
  •  Advanced queuing to match the high performance requirements of real world enterprise applications.
  • Push component upgrades including Java Messaging Service (JMS) integrations, and various transport mechanisms based on browser support.
  • Own Component Development Kit (CDK).
Look into the demo page to find out new components with source xhtml page and Bean classes. (http://richfaces-showcase.appspot.com/)

How to add Richfaces 4 and start using it!
Must follow the below link for migrating from Richfaces 3.3.3 to Richfaces 4:
I am writing few important hints during startup of migration:
  • Adding Richfaces 4 in maven based project:
Here is a snippet from pom.xml
<properties> 
<!-- for Alhpa versions it was just 'ALPHA2' -->
<org.richfaces.bom.version>4.0.0.Final</org.richfaces.bom.version>
...
</properties>

<dependencyManagement>
<dependencies>
<!-- Ricfaces 4.0.0.Final -->
      <dependency>
                                <groupId>org.richfaces</groupId>
                                <artifactId>richfaces-bom</artifactId>
                                <version>${org.richfaces.bom.version}</version>
                                <scope>import</scope>
                                <type>pom</type>
                </dependency>
                <dependency>
                                <groupId>org.richfaces.ui</groupId>
                                <artifactId>richfaces-components-ui</artifactId>
                                <version>${org.richfaces.bom.version}</version>
                </dependency>
                <dependency>
                                <groupId>org.richfaces.core</groupId>
                                <artifactId>richfaces-core-impl</artifactId>
                                <version>${org.richfaces.bom.version}</version>
                </dependency>
                <dependency>
                                <groupId>org.richfaces.cdk</groupId>
                                <artifactId>annotations</artifactId>
                                <version>${org.richfaces.bom.version}</version>
                                <scope>provided</scope>
      </dependency>
</dependencies>
</dependencyManagement

  • Web.xml
1. RichFaces Filter not needed anymore as RichFaces 4 uses JSF 2 System Events for configuration and requests handling.
2. Remove org.ajax4jsf.VIEW_HANDLERS context parameter. it was needed to configure facelets view handler for JSF 1.2 only.
3. org.richfaces.SKIN changed to org.richfaces.SKIN
  • Design of xhtml page:

The xhtml file should look like this, with proper <h:head> and <h:body> tags.
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:rich="http://richfaces.org/rich"
      xmlns:a4j="http://richfaces.org/a4j"

<h:head>
</h:head>

<h:body>
<ui:composition>
</ui:composition>
</h:body>

</html>
As in Richfaces 3.3.3, used to write tags like <head></head> and <body></body>, now within these tags only JSP components rendered.

  • Dynamic components:
Now to create a component dynamically in Java class we need to use UI component. Html components are not available to use in Java classes.
For e.g. to create <rich:column> dynamically used to do like below:

import org.richfaces.component.html.HtmlColumn;
                                HtmlColumn column = new HtmlColumn();                            

                Now we need to use UI component like below:
import org.richfaces.component.UIColumn;
Application app = FacesContext.getCurrentInstance().getApplication();
UIColumn col = app.createComponent(UIColumn.COMPONENT_TYPE);

I will keep updating further issues and solutions to it!
All the best! :)

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Walgreens Printable Coupons