| By Max Katz | Article Rating: |
|
| September 8, 2009 08:00 PM EDT | Reads: |
6,569 |
During my RichFaces session at JBoss World 2009, I showed three small examples of using Ajax with RichFaces 3.3, JSF 2, and RichFaces 4. I thougth it would be a good idea to show you the difference or more correct the similarities between the three. I will be blogging more about RichFaces 4 and JSF 2 so this is just a quick introduction.
I will show a small “Echo” application. There is one input field and as as you type, the input is echoed on the next line. On another line, the length of the string entered is counted. It looks like this:

RichFaces 3.3
<h:form> <h:panelGrid columns="2"> <h:outputText value="Text:" /> <h:inputText value="#{echoBean.text}" > <a4j:support event="onkeyup" action="#{echoBean.countAction}" reRender="text, count"/> </h:inputText> <h:outputText value="Echo:" /> <h:outputText id="text" value="#{echoBean.text}" /> <h:outputText value="Count:" /> <h:outputText id="count" value="#{echoBean.count}" /> </h:panelGrid> </h:form>
Managed bean:
public class EchoBean { private String text; // getter and setter private Integer count; // getter and setter public void countAction() { count = text.length(); } ... }
Bean is registered in JSF configuration file (not shown).
JSF 2
<h:form> <h:panelGrid columns="2"> <h:outputText value="Text:" /> <h:inputText value="#{echoBean.text}" > <f:ajax event="keyup" execute="@form" render="text count" listener="#{echoBean.countListener}"/> </h:inputText> <h:outputText value="Echo:" /> <h:outputText id="text" value="#{echoBean.text}" /> <h:outputText value="Count:" /> <h:outputText id="count" value="#{echoBean.count}" /> </h:panelGrid> </h:form>
Managed bean looks slightly different as instead of an action (see example above) we use a special Ajax listener:
@ManagedBean(name="echoBean") @RequestScoped public class EchoBean { private String text; private Integer count; public void countListener (AjaxBehaviorEvent event) { count = text.length(); } }
RichFaces 4.0
<h:form> <h:panelGrid columns="2"> <h:outputText value="Text:" /> <h:inputText value="#{echoBean.text}" > <a4j:ajax event="keyup" render="text,count" listener="#{echoBean.countListener}"/> </h:inputText> <h:outputText value="Echo:" /> <h:outputText id="text" value="#{echoBean.text}" /> <h:outputText value="Count:" /> <h:outputText id="count" value="#{echoBean.count}" /> </h:panelGrid> </h:form>
Managed bean is same as in JSF 2.
- Ajax features in JS2 are very similar to what’s been available in RichFaces for a couple of year. The JSF standard continues to evolve by assimilating the best ideas in the community into the standard. A perfect example is how the Ajax support in JSF 2.0 almost matches that of RichFaces.
- a4j:support has been replaced with a4j:ajax in RichFaces 4
- a4j:ajax has all the functionality of standard JSF 2 Ajax tag with many additional features to give you more flexibility and power available only in RichFaces.
- For example, features such as client queues, more control on deciding what to process and render, defining parts of a view to always render and much much more.
Published September 8, 2009 Reads 6,569
Copyright © 2009 Ulitzer, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Max Katz
Max Katz is a Senior Systems Engineer at Exadel. He has been helping customers jump-start their RIA development as well as providing mentoring, consulting, and training. Max is a recognized subject matter expert in the JSF developer community. He has provided JSF/RichFaces training for the past four years, presented at many conferences, and written several published articles on JSF-related topics. Max also leads Exadel's RIA strategy and writes about RIA technologies in his blog, http://mkblog.exadel.com. He is an author of "Practical RichFaces" book (Apress). Max holds a BS in computer science from the University of California, Davis.
- Apple Should Buy Adobe
- Jobs Has a Few Words for Google & Adobe & They Ain’t Pretty: Reports
- Can You Fire a Team?
- UPDATE: Adobe & IE Implicated as China’s Spy Holes
- Adobe Flash on the Road to Nowhere
- Apple and Emotional Discussions Around Adobe Flash Player
- LiveCycle Goes Cloud
- Roundarch Uses the Cloud and Adobe FLEX to Deliver Global Experiences
- On2 Stockholders Approve Merger with Google
- Open Source Alternatives to LiveCycle Data Services
- The Free Nuance PDF Reader - Smaller, More Secure and First to Link PDF Desktop with Cloud-Based PDF Conversion Service
- KIKUSEMA GMBH/AB NOMINIERT ALS EINER DER 10 FINALISTEN DES WETTBEWERBS "INNOVATIVSTES UNTERNEHMEN AUF DER RSA® KONFERENZ 2010"
- Apple Should Buy Adobe
- Jobs Has a Few Words for Google & Adobe & They Ain’t Pretty: Reports
- Can You Fire a Team?
- How to Secure REST and JSON
- UPDATE: Adobe & IE Implicated as China’s Spy Holes
- Adobe Flash on the Road to Nowhere
- Apple and Emotional Discussions Around Adobe Flash Player
- Apple Tries Pissing on Google’s Shoes
- The Roadmap for Adobe LCDS 3
- How to Prevent Flex Numeric Nulls From Turning to Zeros in BlazeDS
- Adobe to Discusses Social Media and Government
- Using Custom Type Marshallers in BlazeDS
- Who Are The All-Time Heroes of i-Technology?
- i-Technology 2008 Predictions: Where's RIAs, AJAX, SOA and Virtualization Headed in 2008?
- AJAX World RIA Conference & Expo Attracts Top Faculty
- An A to Z for the RIA Era
- AJAX, RIA, Rich Web Technologies and iPhone Developer Summit Call for Papers Deadline January 25, 2008
- AJAXWorld Conference $250 Savings Deadline Expires Friday, August 17
- Moving Beyond AJAX: 2008 Is the Decision Year For RIAs
- Three RIA Platforms Compared: Adobe Flex, Google Web Toolkit, and OpenLaszlo
- Rich Internet Applications vs AJAX: "2008 Will Be A Crucial Year"
- Building an iPhone Application with Adobe AIR
- Data Services Made Easy for Adobe Flex Applications
- SYS-CON.TV Exclusive: Jeremy Geelan Interviews Adobe's Kevin Lynch























Ulitzer content is offered under Creative Commons "Attribution Non-Commercial No Derivatives" License.
For any reuse or distribution, you must make clear to others the license terms of this work.
The best way to do this is with a link to this web page.
Any of the above conditions can be waived if you get written permission from Ulitzer, Inc., the copyright holder.
Nothing in this license impairs or restricts the author's moral rights.