What RichFaces a4j:ajax adds on top JSF 2 f:ajax tag

JSF 2 now has basic Ajax support via f:ajax tag. RichFaces 3 has a very popular a4j:support tag (in fact, f:ajax was inspired by a4j:support). RichFaces 4 comes with a4j:ajax which is based on f:ajax but upgrades the tag with more features and advanced functionality. The table below show the attributes available in both tags and how RichFaces upgrades the core Ajax functionality in JSF 2 (I’ll cover a4j:ajax extra attributes in the future).

In addition to a4j:ajax, RichFaces upgrades JSF 2 with tags such as a4j:commandButton, a4j:commandLink, a4j:poll, a4j:jsFunction, a4j:outputPanel and more (covered in future posts).

Attribute f:ajax a4j:ajax
event Works the same Works the same
execute @all
@this
@form
@none
Id’s
EL
@all
@this
@form
@none
Id’s
EL (different behavior, id’s are resolved in current request)
@region (when a4j:region is used)
render @all
@this
@form
@none
Id’s
EL
@all
@this
@form
@none
Id’s
EL (different behavior, id’s are resolved in current request)
listener Works the same Works the same
onevent Works the same Works the same
onerror Works the same Works the same
immediate Works the same Works the same
disabled Works the same Works the same
onbegin n/a JavaScript to execute before Ajax request
onbeforedomupdate n/a JavaScript to execute after response comes back but before DOM update
oncomplete n/a JavaScript to execute after DOM update
bypassUpdates n/a Skips Update Model and Invoke Application phases, useful for form validation
limitRender n/a Skips all a4j:outputPanel ajaxRender=”true” areas. Only renders what is set in current render
status n/a Status to display during Ajax request
focus n/a Sets focus on component after Ajax request (not yet implemented)

Learning JSF2: Using Flash scope

JSF 2 provides two new scopes on top of the standard Servlet scopes (request, session, application). One of them is the view scope. View scope was covered in Managed beans article. The other scope is Flash which I’m going to cover here. Let’s start with a very simple example.

Managed bean:

@ManagedBean(name = "bean")
public class Bean {
   private String text;
   // getter and setter

   public String nextpage (){
       return "page2";
   }
}

As scope is not specified, the default scope is request.

JSF page (page1.xhtml):


   
	
	
	
   

Continue reading

Learning JSF2: Page params and page actions

Learning JSF 2 series continues with page parameters and page actions. Read other Learning JSF 2 articles.

If you worked with JSF 1.2, you know that calling a page action wasn’t simple. A page action is useful when you request a page for the first time (GET request) and would like to prepare some data to be rendered on a view (page). Of course there are some workarounds, one of them is to use @PostConstruct method inside the bean or even create a phase listener. Both could work but developers desired a more robust, and out of the box solution similar to what Seam 2 provides. Continue reading

JSF 1.2 Components: book review

JSF 1.2 Components by Ian Hlavats.

Chapter 1: Standard JSF components

Chapter 1 starts by covering standard JSF UI components. It covers all the categories of standard components in JSF: input, output, selection, tables and layout. Examples are short, self-contained, and very easy to follow. Ian does an excellent job of describing various features and attributes of the components and their usage. His explanations are very easy to follow.

Chapter 1 summary says that it covered some of the key concepts behind JSF however, I didn’t see coverage of JSF managed beans, navigation, event listeners, and the JSF life cycle.

Chapter 2: Facelets

Chapter 2 covers Facelets and I think it’s the best Facelets coverage that I have seen. Good examples, easy to follow. I think all JSF 1.x books were published before Facelets became a de facto standard view technology, so this is the missing chapter for all of them. Chapter 2 starts with some interesting historical information on JSP and why Facelets was created. Again, excellent chapter and coverage of Facelets.

Chapter 3: MyFaces Tomahawk components

Chapter 3 covers MyFaces Tomahawk components. The chapters covers some of the most popular and interesting components in Tomahawk such as calendar, jsfCookMenu, upload file and tree. I was glad to see more backing bean code for some of the Tomahawk examples.

Chapter 4: MyFaces Trinidad

This chapter covers MyFaces Trinidad components. As with the standard JSF components and the MyFaces chapter, this is a general overview a description of the usage of some Trinidad components. Ian does a good job explaining how the components work and provides short examples. I like shorts examples because it’s easy for the reader to try them in his or her application without having go to through a large number of steps.

Chapter 5: IceFaces

There is not as much to say about chapter 5 which covers IceFaces JSF components. I would have liked to see some coverage of the IceFaces Direct-To-Dom approach, which really makes IceFaces different from libraries such as Trinidad and RichFaces.

Chapter 6: Seam

The Seam chapter starts with an introduction to Seam and why it was needed. It then goes on to explain Java EE and its components such as EJB3 and JPA. I think it’s a very good (brief) introduction for anyone who is just starting with Java EE. Then the chapter goes on to cover some of the Seam tags. Explanations are good and the examples are easy to follow. The first example shows how to delegate validation to the Hibernate Validator using Seam’s s:validate tag. Other tags are covered as well, such as s:label, s:span, and s:message.

The chapter them moves on to show how to add Ajax with the RichFaces a4j:support tag. (The actual RichFaces chapter comes after this chapter.) I think it would have been better to cover RichFaces, including a4j:support first, and then Seam.

The second part of the chapter is mostly dedicated to covering Seam conversation support. The chapter shows some good examples but feels a little bit out of place. I just don’t view the conversation as being part of the UI. There is also an example that puts navigation rules for controlling the conversation into a standard JSF descriptor file (faces-config.xml) instead of Seam’s descriptor file (pages.xml). Seam’s documentation recommends using only the pages.xml file for storing the navigation rules in a Seam application..

All in all though, it’s a good chapter on some of the core Seam features for JSF.

Chapter 7: RichFaces

The last chapter is on RichFaces and is the most interesting to me personally as I have myself published a book, Practical RichFaces on this subject. The chapter starts with a quick introduction to Ajax4jsf and RichFaces. This chapter is on par with the other chapters. It provides a high-level overview of some of the components from the rich: and a4j: tag libraries. Components covered include rich inputs, panels, menus, data iteration as well as Google Maps and Microsoft Virtual Earth. From the a4j: tag library, a4j:poll and a4j:commanLink are covered.

I was somewhat disappointed to not see a4j:support tag coverage here. (a4j:support was instead covered briefly in Seam chapter.) I think it’s one of the most important tags in the library and probably the tag that made the whole framework popular. Also, the f:ajax tag from JSF 2 is closely based in concept to a4j:support.

In general, the chapter is well written and provides some good examples of various RichFaces components and concepts.

Summary

First of all I want to congratulate Ian on this book. He did an amazing job. I personally know the time, dedication, and other resources need to write a book. The book provides a good, general overview of the most well-known third-party components as well as the standard JSF components. The examples are easy to follow and self-contained (which means it’s easy to run them) with explanations that are very clear.

My biggest question is who is the audience for this book? If you are just starting with JSF, then this book doesn’t go deep enough into the core features of JSF as well as the covered component libraries. You need at least a regular JSF book. If you are already an experienced JSF developer, then it could be a good read to quickly cover various 3rd party component libraries and see what’s available. But again, this is going to be your second book. If you are a manager, this could be a book you could read to get a high level overview of the various components in the JSF ecosystem.

Anyway, a great contribution by Ian Hlavats to the JSF community. Congratulations!

RichFaces 3.3.3 is released!

Congratulations to RichFaces team for releasing version 3.3.3. Although this version has basic JSF 2 support, if you are using JSF 1.2 you can upgrade to this version as it has the latest bug fixes and other improvements. With this release, the entire RichFaces team is now focused on pushing RichFaces 4.0 release out.

You can also check out Alex Smirnov’s (RichFaces architect, Exadel) post on portlet bridge support for this version and JSF 2.