JavaServer Faces - Book shootouT

Damodar Chetty

August 17, 2008

JavaServer Faces has been around for long enough for over a dozen books to be written about it. The downside of having so many sources is that you now have to make a real decision about how to spend your limited dollars, and more importantly, your time.

Well, the intent of this shootout is to do some of this work for you. I will do a compare-and-contrast of some of the most popular books available today to try and identify the best book to buy for your bookshelf.

The first step then is to pick these books.

I started at Amazon.com and ranked the available books using two measures:

  # of reviewers, which is indicative of a book's popularity; and

  average rating per user.

As I write this, the ordering in Amazon appears as:

 

Stars

#Reviewers

Core JavaServer Faces - by Geary and Horstmann, 2007 (752 pages)

4

31*

JavaServer Faces by Hans Bergsten, 2004 (624 pages)

3

24

JavaServer Faces in Action by Kito Mann, 2005 (702 pages)

3.5

20

JavaServer Faces: Complete Reference by Schalk et al, 2006 (864 pages)

4.5

10

Mastering JavaServer Faces by Dudney, et al, 2004 (480 pages)

3.5

9

*Aggregates reviews from the previous edition.

I will consider these books from the viewpoint of a web developer wishing to pick up JSF skills. For now, I do not compare the treatment of advanced topics, such as custom component development, phase and data model events, etc.

I'll compare these books using the following axes of comparison:

a.    JSF architecture and conceptual background.
Includes coverage of the patterns that underlie JSF, comparison with competing frameworks, and descriptions of key JSF architectural components.

b.    Request processing
The JSF request lifecycle can be daunting to beginners, there's so much happening, and so many ways to short circuit processing that it can leave you feeling disoriented.

Here, I focus on clarity of explanations of the different phases, including life cycle scenarios depending on different request/response combinations.
I also consider descriptions of conversion and validation, incl. the creation of custom converters and validators.

c.    Templating
Here I compare how well the book describes the interaction between JSP and JSF, the standard JSF components, and alternative composition solutions.

d.    Navigation and Event handling (value and action)
Here I look at the description of the navigation algorithm and the JSF event model.

e.    Miscellaneous
This compares coverage of topics such as security, internationalization, and error messaging.

f.     Example code
Here we look at the quality of the example code provided in terms of its applicability in real life, ease of following along, etc.

 

 

1. JavaServer Faces IN Action

Kito's book targets current Java web developers who want to learn JSF, i.e., people who are already familiar with JSP and servlets. So forget about getting any hand holding with setting up a servlet container, or a gentle introduction to HTTP, servlets, or JSP.

1.1.1. Architecture (5 out of 5)

This book takes the prize in the area of general architecture it covers an amazing amount of ground, both with using the JSF components as well as deep into JSF's internals.

I'm a visual person, and found his diagrams to be a particular treat. One of the first provides a birds eye view of a JSF application. If you take the time to savor it, you'll get a very comprehensive view of a JSF web application's place in its world.

Another diagram terminates a discussion on what frameworks bring to the table - this time its a depiction of web application infrastructure as a stack of services. It clearly depicts the benefits that accrue from using JSF, vs. say coding directly using the servlet API. The Struts stack is overlaid there as well - so you get a nice comparison of the two frameworks. This section is a must read for web developers.


Unfortunately, his first application is a bit over the top. There's a lot of code here for a "Hello World" application, and it doesn't help that he starts with a flourish - you're dynamically adding controls to a component using an action listener! Not good.

Fortunately, his class model of the various JSF components is another must see. Its a very informative overview with the UI Component as the center of attention, surrounded by its minions.

The second chapter is another gem - it provides a detailed description of the various classes that comprise JSF. There's a lot to take in, so its likely you'll have to revisit this often while you read the book.

Unfortunately this is a recurring theme in this book. The topics jump from low level details to high level overviews and back again, so much that I couldn't read this book linearly, and had to backtrack ever so often to find my bearings.

In the spirit of the seemingly haphazard organization of this book, one of the most engaging chapters on general JSF architecture is placed right at the end (chapter 11). There you will find another excellent diagram that maps all of JSF's application classes, grouped into 4 categories - component classes, context classes, application classes, and event handling classes.

The UI Component's singular importance in JSF is honored by an entire chapter. A table classifies components by family (input, output, etc.), JSF implementation class (UIInput, UIOutput, ), and HTML subclass (HtmlInputText, HtmlOutputLabel, ).

1.1.2. Request Processing (5 out of 5)

Coverage of the life cycle stages is very detailed and informative.

A key concept in JSF is that of component and client identifiers - which define how naming containers influence the name of a child component in the rendered HTML. This is very clearly portrayed, by yet another diagram that maps the component tree on the server to form components on the client.

The coverage of converters and validators is just as complete - including creating custom converters and customizing error messages using message bundles.

1.1.3. Templating (4 out of 5)

It adequately covers the use of JSP actions, custom actions, and JSTL within a JSP page. A nice touch is that, each standard JSF component is accompanied by examples of how it would be rendered in HTML, and how a browser might display it. This gives you, for example, a clear picture of the additional scripting added for a <h:commandLink> component. There's also above average treatment of the building blocks of selection lists - UISelectItem and UISelectItems.

1.1.4. Navigation and Event Handling (3 out of 5)

This information is spread out across multiple chapters - not something that I prefer. While no details are lost its still a bit of work to piece together the whole story. For example, the default ActionListener is covered a number of chapters away from the topic on declaring an action listener.

1.1.5. Miscellaneous (5 out of 5)

Interestingly, this is one of the rare books that addresses a rarely considered concept - which JSF implementation should you choose. The RI is a reasonable choice, but the larger question is when an alternative implementation such as MyFaces would be preferable.

The Managed Bean Creation Facility is an interesting implementation of inversion of control. He provides guidelines as to which objects should be constructed using this facility, and which ones would be better served by initialization at web application startup - say using a ServletContextListener, so as not to incur inordinate delays in the middle of a user's interaction. And there's even an example later on in the book, if you didn't get the hint.

Internationalization coverage is pretty complete - in terms of configuration in faces-config.xml (and a warning that without these locale-config elements, the JSF implementation may only support the default locale of the application's JVM); determining the user's locale (using the <f:view> tag, Java code, or the browser's locale settings); and creating resource bundles to house your locale specific properties.

This book is peppered with relevant tips such as the warning here that you can't use the "." character in resource bundle keys.

It also describes the use of <f:loadBundle> in the template page, especially the use of the basename attribute and how it is set based on where in the classpath the resource bundle is located. For bundles located in WEB-INF/classes no prefix is necessary - since that's the root of the classpath. However, bundles any deeper than that require to be prefixed appropriately.

Another rare topic for a JSF book is the creation of a global error page and registering it in web.xml and as a global navigation rule.

Finally, there's an example of the use of a servlet filter for security.

1.1.6. Examples (3 out of 5)

While I typically don't favor overblown monolithic projects that require you to follow along across multiple chapters, the provided example has all the bells and whistles of a typical application you might encounter - including user roles, workflows, and a common toolbar component.

In addition, Kito provides a really interesting approach to application development - by starting out with a dummy user interface using hard coded beans and static navigation outcomes, and slowly evolving the application.

Unfortunately, the result is a bit uneven - the first couple of chapters flow wonderfully. However the latter chapters of the examples feel a bit hurried, especially once we're into the more difficult aspects of JSF development.

1.1.7. Conclusion (overall score: 4.2 out of 5)

You'll be hard pressed to find a book that has such excellent coverage of so many diverse topics.

You'll also find gems of practical advice throughout the book - for e.g., that you have 3 alternatives as to where to place your action methods (in your backing beans, within independent action classes, or within service classes) along with the tradeoffs associated with each.

Unfortunately, I'm not a big fan on how the topics are organized. I had to keep jumping back and forth - many many times, and that got to be very tiresome. It is hard to use this as a reference book given the large geographical distance between related concepts. This may actually fare better as a search-able e-book.

This is one of the best examples that you'll see (though marred by uneven pacing) - rivalled only by the example that Hans provides.

2. Core JavaServer Faces

This book is targeted at users with basic HTML and Java programming skills, so its also very accessible to newcomers, with coverage of beginner details such as installing an application server (GlassFish).

It is also one of only two books (Schalk's is the other) that is updated to cover JSF 1.2. Unfortunately, the coverage is not as complete as Schalk's.

2.1.1. Architecture ( 3 out of 5)

The book wastes no time in getting started with installing GlassFish and building a Hello World type login application. In the space of a few pages, you get a very comprehensive high level introduction to JSF. There's a lot of ground covered here, (such as building a WAR, deploying to GlassFish, and crafting deployment descriptors), but the explanations are gentle enough for most purposes.

I'm not a fan of the diagramming style with the busy grid background - but that's purely a subjective issue.

This is one of the few books that tries to distinguish between normal beans and backing beans (which directly hold UIComponent instances as properties). This distinction feels largely academic - but its an interesting semantic nonetheless.

I also like the concurrency warnings provided - developers often overlook the fact that objects in a user's session are not thread safe.

2.1.2. Request Processing (4 out of 5)

The slow-mo following of a request from the browser and through JSF's life cycle is interesting, although a tad bit late (its in chapter 6). Its the clearest explanation I've seen of how a "request value" from a form field carried in the HttpRequest transitions into the UIComponent object's "submitted value"; then making it through a conversion process to coax it into the appropriate type; after which that typed value being stored as the UIComponent object's "local value"; then moving it through a validation process; and finally storing it in the component's "model bean value".

And, more importantly, it provides a reason for why this 2-step process is necessary (prevents model values from being updated when the request value is invalid).

Conversion and validation get pretty standard treatment. However, the display of localized conversion errors from message bundles is described in wonderful detail.

2.1.3. Templating (4 out of 5)

The treatment of the standard JSF tags is complete and engaging. This is probably the most efficient categorization of attributes (common, pass through, and DHTML event); why a simple expression of the form documents.forms.registerForm.password won't work in client side Javascript; along with tons of examples of each tag in the form of tiny, but full fledged, web applications.

This chapter will serve as a good reference guide for months to come.

Particular mention must be made of the chapter on data tables, which gives you more detail than I've seen anywhere else (other than Hans's book) - with some great looking table content, editable input components and graphics; adds, edits, and deletes of rows; and with sorting and scrolling options.

As a bonus it includes coverage of Facelets - a very welcome addition.

2.1.4. Navigation and Event Handling (4 out of 5)

The description of the navigation algorithm is the most comprehensive treatment that I have come across yet. The use of the <redirect/> tag is also portrayed very clearly - with screenshots that show how the URL changes on a redirect.

The event handling is just as comprehensive, and since this book is updated to JSF 1.2, we now have treatment of the f:setPropertyActionListener action which is really handy for extracting parameters from the incoming request and setting it on beans.

While immediate command components (e.g., the Cancel button) are common in most books, there is coverage here of immediate input components as well. The explanation is done better in Schalk's book.

2.1.5. Miscellaneous (5 out of 5)

Internationalization coverage even includes the use of the JSF 1.2 <resource-bundle> parameter which lets bundles be defined in your faces-config.xml. However, it does not explain this parameter as well as Schalk's book does.

The spinner component has an interesting aside where a JavaScript function is bound to a text input control, enabling us to avoid name conflicts when defining global JavaScript functions.

There is a wealth of information on ancillary topics such as database access via JDBC and configuring database resources in GlassFish and Tomcat; an introduction to LDAP using OpenLDAP; container managed security; and even invocation of Amazon web services.

It is also one of the rare books to cover Ajax - both from first principles, using the Prototype JavaScript library, DWR, and JBoss Ajax4jsf/RichFaces.

Finally, there's an interesting "How do I ..." chapter that provides answers for common questions, such as how to handle file uploads, and how you might store beans longer than request scope but less than session scope (using Apache Tomahawk's saveState component, or the JSF extensions project's flash scope implementation).

2.1.6. Examples (2 out of 5)

Interestingly, even though I actually prefer smaller example projects, the examples in this book were either too trivial to be interesting or too complex for a quick read. So, I found myself skipping over a lot of the code, without getting as much from it as I'd have liked.

2.1.7. Conclusion (overall score: 3.7 out of 5)

The book tries real hard to cover everything and the kitchen sink. Unfortunately, this means that there isn't as much depth as one might like. For e.g., the topic on Facelets composition barely scratches the surface, and only covers usage of the ui:composition, ui:insert and ui:define tags.

Another problem is the lack of heft with describing the internal architecture of JSF. One might argue that beginner's don't really care about that, but then one might counter that you can't be a productive JSF developer without knowing how it works at some level of detail.

The organization of content is very thoughtfully done, making it easy to find a topic of interest and brush up on it, as required.

The examples are designed to encapsulate individual concepts, and aren't good enough to show you what a decent production grade application might look like. So there's no direct help for use on a live project.

Its coverage of the JSF 1.2 spec is very welcome but it feels tacked on, as there's no in-depth discussion of the new features.

3. Mastering JSF

 

Given that this book was written in 2004, it feels a bit worn. At 480 pages, its also one of the thinnest books on the topic, which excited me because most books inflate their page count by including nothing more than JavaDocs. (Its akin to puffing up your chest to look bigger.)

3.1.1. Architecture ( 3 out of 5)

A unique aspect of this book is that it begins with the staple patterns that JSF embodies, such as MVC, Composites, and Observer. It highlights how JSF's implementation of a pattern differs from other implementations that the reader might be more familiar with (such as Swing and Struts).

It also takes a leisurely stroll through the JSF building block concepts - such as component families, component trees, and component identifiers. Unfortunately, the treatment is largely superficial.

It makes a distinction between Component Models and Application Models, which when taken together with the JSF Model-2 architecture diagram in the first chapter, clarifies a basic area of confusion among new JSF developers.

Unfortunately, the book shows its age. It deals with JSF 1.1, and provides a detailed description of deployment of web applications, but is written for Tomcat 5.x.

While it took the scenic route for over a hundred pages, in part 2 of this book you are hurriedly dumped into tons of dense source code (starting with two faces-config files). You're then provided a detailed walkthrough of the various faces-config elements, and then you look at TLD files. All this before you've even written a Hello World application! While the description is fairly thorough - it seems an odd placement choice.

The chapter on UIComponent is comprehensive, but feels muddled. Concepts that were introduced earlier (such as event listeners and validators) are discussed yet again, and then there are future chapters that refer to these in yet more detail.

3.1.2. Request Processing (3 out of 5)

The JSF life cycle can be very overwhelming, and this book takes a different tack to making it approachable. It considers the different types of requests and response combinations (JSF, and non JSF), and for each combination paints the appropriate life cycle. This results in cleaner diagrams than usual - where you'd otherwise end up with a hodge podge of lines, dotted lines, dashed lines, etc. For example, when a non faces request results in a Faces response, there are only 2 boxes of the life cycle that are relevant.

I also liked its description of how/when to use renderResponse() and renderComplete() to short circuit the life cycle.

Shortly thereafter, you get the full treatment of each life cycle phase, in glorious detail. This depth is atypical of most books, and one might argue that it is overkill for application developers, but as I've said before there's value to be had in getting a deeper understanding of the framework.

The section on conversion provides a very useful sequence diagram on how values are converted both during decoding and encoding. This is one of the clearest representations of this process. There's also a very handy table that maps Java classes to their associated converters. Unfortunately displaying of error messages is not covered as completely as in other books.

3.1.3. Templating (2 out of 5)

This topic provides a very comprehensive look at what happens to JSP pages during the render response phase - both for new requests, and later post-back requests. One of the interesting aspects if you are doing JSP is the role that the <view> tag plays in saving state in the response. In addition, it walks through the steps taken by a typical UI Component tag when its doStartTag() is called.

Unfortunately, you don't get details or examples of usage of even the standard JSF components.

3.1.4. Navigation and Event Handling (3 out of 5)

Coverage here is adequate, but not spectacular.

3.1.5. Miscellaneous (0 out of 5)

There isn't anything that wows you in terms of additional ancillary material. There is a surprising lack of information on internationalizing your application, and there's no discussion of alternative templating strategies.

3.1.6. Examples (1 out of 5)

The smaller examples (such as the one in the chapter on JSP integration) are not specified in a "follow-along" manner, and you'll have to connect the dots to get it to work. I understand that the code is available online, but I prefer all the bits and pieces I need to be available as I'm reading a book.

The general quality of the examples also was not quite up there with the rest.

3.1.7. Conclusion (overall score: 2 out of 5)

The first 100 pages of this book focus on high level architectural concepts. While this is great for those who already understand the basics, I would have preferred to start with a more hands on approach.

The best way to use this book is to go get the source code from their web site, and then follow along as best you can with the information in the chapters. The downside with this approach is that you have to deconstruct a fully functional application, rather than having the luxury of adding to it bit by bit. The effectiveness of this book will depend on how well this usage works for you. It didn't work that well for me.

There were more frustrating moments with this book, given its organization and lack of breadth, compared to the other books reviewed here.

Overall, this book did not fare well on a number of criteria, and once more underscores the importance of limiting the number of authors to 2 or fewer.

 

4. JavaServer Faces - O'Reilly

This is one of the oldest books, and is based on the JSF 1.0 spec. Despite its age (4 years is an eternity in software development), this book is still an excellent introduction to JSF.

Its also very prescient in terms of using alternative ViewHandlers to make JSF templates look very similar to pure HTML.

Hans was very vocal about the disconnect between JSP and JSF and you will find a number of articles on the web that discuss this issue.

4.1.1. Architecture (3 out of 5)

This book takes the time to spell out exactly how JSF improves upon plain servlets/JSP. For e.g., less code in the template because you can replace a lot of iteration and conditionals when rendering a simple set of check boxes; and the fact that JSF components are just perfect for handling complex dynamic state and so are ideal for complex user interfaces.

It is the only book that truly starts at the beginning - with the installation of the JDK ... unfortunately, this is JDK 1.4. There's even discussion of the HTTP protocol, the structure of requests and responses, the role of web containers, and of servlets, filters, listeners, JSP, and even container based authentication schemes. This is great if you are new to J2EE web development, and need a quick introduction.

There's even discussion of naming containers and component IDs, and how the view that created the response containing the form is also responsible for processing the submitted form - i.e., that the URL for the form's action is automatically set by the JSF form tag.

The topic of backing beans (i.e., where the binding attribute is used to directly tie a UIComponent to its bean) is accompanied by an explanation why this violates separation of concerns between the application logic and UI components. He makes the case that you should avoid this whenever possible.

Unfortunately, this book does not contain a detailed dissection of JSF internals.

4.1.2. Request Processing (3 out of 5)

The request processing life cycle coverage is adequate. Oddly enough, the first time you'll see the request life cycle is in Chapter 8, but it still reads well, and all the relevant information is present.

Validation and conversion are also covered well, and there's even customization of error messages covered.

4.1.3. Templating (3 out of 5)

The coverage of JSP templating is pretty thorough. Though there isn't a whole of descriptions of the standard tags.

The chapter on data tables is an exception. You'll find a plethora of options to customize the data table component as you'd like. E.g., you can even change the component displayed in a column depending on the data of the current row.

The discussion on composition using JSP includes (the directive and the action) as well as Tiles is also very well done.

In particular his guidance regarding JSF and including multiple forms on a single page is a worthwhile read.

4.1.4. Navigation and Event Handling (4 out of 5)

The JSF event model is discussed in terms of its components - the event classes, listener interfaces, event handlers, and event sources - which gives you an amazing depth of insight into how this is put together.

An interesting classification of events is in terms of whether they are UI events (i.e. action events that only affect the presentation tier; or value change events), and whether they are backend events (i.e., change the application model).

Another unique tidbit of information is how the immediate=true attribute for an event source maps to a phaseId property of a FacesEvent, and controls the firing of events. Note that its the clarity of this relationship that's unique.

You'll find an interesting example of an action event that only affects presentation, where a single command button's event handler toggles the list of items available in a selection list, and which uses the immediate attribute to short circuit the life cycle.

There's also a variant, where the action event/command button are replaced by a value change handler/checkbox combination.

Navigation handling is stepped through adequately. It is worth noting his example of using a JSF handler to produce a non JSF response. This is one of the clearest use cases for invoking responseComplete() to prevent JSF from rendering the response. The chapter is rounded off with a code snippet of generating a JSF view in Java code.

4.1.5. Miscellaneous (3 out of 5)

While saying that thread safety is out of scope, it still manages to get a few words in about thread safe design (watch out mutables in application and session scope).

There are lots of useful tips - such as externalizing component rendering decisions out to Java classes rather than encoding these business rules into the templates.

Note the addMessage() method in chapter 8 which localizes messages using the application's resource bundle and the locale from the current view, and adds the message to JSF's message queue. This is also used in Chapter 7 to localize validator exceptions.

The coverage of internationalization is also very complete. There's an important warning that while you can programmatically set the UIViewRoot's locale, you must do it only after the Process Validations phase and before the Render Response phase. There's also the requisite warning against using a "." in resource bundle keys.

He also talks about how JSF input components automatically use the current locale when they parse input, such as dates, currencies, etc.

This is also the only book to discuss support for non western languages using Unicode - something of deep interest to me.

4.1.6. Examples (4 out of 5)

The overarching example here is an expense reporting application that is a great demonstration of the power of JSF in creating a feature rich application. It involves authentication, authorization, user roles, workflow ... the works.

Its Achilles heel is that it ends up largely being a single screen application - which isn't quite your typical real world case. The only navigation logic is in the Preferences link - which leads to a three screen workflow.

4.1.7. Conclusion (overall score: 3.3 out of 5)

An oddity is the use of the term "glue bean" to refer to "managed beans".

There isn't as much practical advice on the use of the standard JSF components as I'd have liked (which is done better in the Core JSF and JSF in Action books).

The writing here is well above average, so its very easy to read.

 

5. JavaServer Faces: Complete Reference

One of authors is Ed Burns - a co-specification lead for JSF, and it came highly recommended by my coworkers - so my expectations were high when I picked this up.

5.1.1. Architecture (3 out of 5)

It begins with a high level overview of JSF, and ends with a discussion of the MVC pattern. There's a premature treatment of navigation - which feels out of place.

There's enough details about installing JSF, as well as on compiling and packaging the application for Tomcat.

The chapter on the Unified EL describes its plan for world domination - where the Unified EL is its own spec and usable outside of the Web tier.

Also, the ValueBinding and MethodBinding classes have been deprecated in favor of ValueExpression and MethodExpression. So, the traditional approach to getting a managed bean via Java code (using either createValueBinding() or resolveVariable()) will now result in deprecated messages. Note that none of the other books cover this material - so this is gold right here.

The authors describe a pattern of usage for backing beans, where each JSF page is associated with a Java class that is registered as a managed bean. They advise against having a many-to-many relationship between backing beans and pages - since the dependencies between the two can quickly spiral out of control, outweighing any benefits that reuse may confer.

The authors make the case that using direct component binding is a workable solution when dealing with transient values that do not need to be passed to the model, or when dealing with simple cases. However, Hans's argument on the separation of concerns seems more persuasive. (This topic has the feel of a religious war to it - so keep your own counsel.)

5.1.2. Request Processing (3 out of 5)

The request processing life cycle is described in loving detail (right down to the specific methods called in the component tree), and is followed by the different request processing use cases. This section is hurt by severe dearth of diagrams.

This is the only book that actually defines the term "postback" - (a form submission) - which has special significance in the JSF world.

The coverage of the immediate attribute is very complete - both in terms of action events (e.g., for Cancel buttons) and for input components (e.g., for value change events). Unfortunately, no real use case was described for the latter case.

The topic of conversion and validation starts with some very expressive diagrams (for a change) that clearly point out the logic involved in this complex process. The algorithm for the selection of a UIOutput's converter or a UIInput's vallidator are also well detailed.

A key advantage is that the examples here use the newer JSF 1.2 ValueExpression and ELContext classes. The problem is that I can't believe that these files ever compiled - on page 128 the constant UNIT_POUNDS has a typo. Twice.

The topic of customizing validation error messages is discussed, but the example provided is fairly incomplete and you are referred to a prior section. Also, the discussion of localizing these messages is deferred to Chapter 12 - which is titled "Building Non-UI Custom Components"! (This was probably a typo - it should have been Chapter 14 - Localization and Accessibility - but it did wake me up.)

5.1.3. Templating (3 out of 5)

An interesting aside shows how all the complaints about JSF/JSP integration were addressed in the JSF 1.2 spec. Now, all template text (including markup) and JSP custom action output are automatically coverted to temporary UIOutput components whose state is not saved - known as "content interweaving". This allows components such as panelGrid and panelGroup to directly lay out static text (wrapped in the temporary UIOutput components) without requiring the developer to enclose them in <f:verbatim>.

The rendering logic now makes one pass solely for building a complete component tree, and then makes another pass to render it in one fell swoop.

The fact that the entire tree has been built before any rendering is done allows you to avoid problems such as having both JSP actions as well as JSF actions fighting to write to the same output stream, and having one component not being able to access another because it has not yet been added to the view.

There's a conspicous absence of treatment of standard JSF tags. The assumption is that you'll be able to figure these out on your own.

To implement sorting and scrolling of data tables, you'll have to look at the example in Chapter 9, where unfortunately there is too much going on for the text to be clear. See Hans's book or Core JSF for a superior treatment. However, I did like how <h:graphicImage>'s url attribute is set appropriately to indicate the sort direction - something neither of the others cared to do.

5.1.4. Navigation and Event Handling (5 out of 5)

The discussion of navigation focuses on the default ActionListener and NavigationHandler - and this time the flow diagram is very useful.

There's also a nice tip here to place your navigation rules in a separate file and to use the javax.faces.CONFIG_FILES context parameter to refer to it.

The JSF event model is described well - in particular figure 8-3 is a gem, and clearly shows where queued events are processed (both for immediate and normal cases).

The writing in this chapter is well above average, and I really enjoyed the anatomy of each event type. In particular, you would do well to heed the warning associated with immediate component handling - since the handler is invoked right away after Apply Request Values, retrieving another component's value is not guaranteed to return valid data unless that component's immediate attribute is also set to true. (Remember that immediate components are validated during the Apply Request Values phase, rather than in Process Validations.)

The examples provided are surprisingly fun, and give you good use cases for value change listeners.

5.1.5. Miscellaneous (4 out of 5)

I loved the chapter on alternative view handlers (also see Hans's book) and the excellent introduction to Facelets.

I was surprised that the localization features were pushed out to chapter 14 - that's almost into afterthought territory. An interesting point it makes here is that you can use <f:loadBundle> multiple times to load additional resource bundles for a given locale - allowing you to split your localized resources by function.

An important note that is not covered in any other book is the performance impact of <f:loadBundle> - which causes the ResourceBundle to be reloaded for each request. A better alternative is to use the new JSF 1.2 <resource-bundle> element which loads the bundle at the application level. This confers other advantages, e.g., that localized values can now be accessed even in other phases, and by Ajax requests.

The description of how locale is determined is also very well done. Its the ViewHandler again, and it relies on the Accept-Language request header and runs matches agains the supported locales and default locale specified in your faces-config.xml.

This is the only book to deal with accessibility - but it devotes all of 4 pages to it! Why even bother?

5.1.6. Examples (2 out of 5)

Yikes! The first "Hello world" example is a multi page application that walks you through myriad JSF components, input validation, and navigation. This is by far the most complex introductory application I've encountered. JSF is complicated enough without needing to rush the learning process - esp. in a book that's over 840 pages.

The examples within each chapter are largely code snippets, and not complete JSF applications - such as you'd see in Core JSF.

Part 2 comprises a Virtual Trainer application, which is a domain that I couldn't quite get excited about. Unfortunately, it is developed in a single chapter. And, even worse, it is not complete and you will have to go online to retrieve the code.

For e.g., methods in JSFUtil and UserUtil which look really interesting are not described in sufficient detail. And, then there are the magic UserRegistry and TrainingEventRegistry that are largely glossed over.

Note that new JSF details are interspersed through this chapter. So, if you don't read this chapter, you'll miss important details.

I also couldn't fathom why they insisted on using the VariableResolver to obtain JSF managed beans when earlier notes indicated that this had been deprecated.

Another oddity is that the logout() action method directly uses the navigation handler to navigate to the welcome page. While it was nice to see this alternative, I couldn't tell why this might have been preferable to using an outcome string.

Also, the entire example is predicated on the fact that you want to directly bind UI components to managed bean properties, via the binding attribute. This may or may not be your preferred approach.

<Nit_Alert>

Then there's the small matter of Java naming convention violation, on page 189:

UserRegistry ManagedUserRegistry = ...;
if (ManagedUserRegistry.AddRegisteredUser(newUser))...

</Nit_Alert>

5.1.7. Conclusion (overall score: 3.3 out of 5)

I earlier complained that the Mastering JSF book didn't get to JSF usage until after a hundred pages. Well this one errs on the other extreme - within 2 dozen pages, you're already knee deep in SelectItems, navigation rules, etc.

For instance, on page 25, it refers to the "none" setting for a managed bean's scope, with no additional information. I found this way too early to introduce the concept of anonymous beans and bean references without confusing the reader.

I was impressed with the clarity with which the differences between JSF 1.1 and 1.2 were presented. There's tons of sidebars that call these out.

The diagrams in the book felt downright amateurish - most of them are composed of rounded rectangles and arrows, many rounded rectangles and many arrows. See Kito Mann's book for what the standard for JSF diagrams should be.

6. Overall Thoughts

Here's a summary of my opinions.

 

Stars

JavaServer Faces in Action by Kito Mann, 2005 (702 pages)

4.2/5.0

Core JavaServer Faces - by Geary and Horstmann, 2007 (752 pages)

3.7/5.0

JavaServer Faces: Complete Reference by Schalk et al, 2006 (864 pages)

3.3/5.0

JavaServer Faces by Hans Bergsten, 2004 (624 pages)

3.3/5.0

Mastering JavaServer Faces by Dudney, et al, 2004 (480 pages)

2.0/5.0

 

It is interesting that after reading through all these books once again to perform a meaningful comparison, I still cannot pick one of these as good enough for all purposes.

However, if I were to work on JSF while marooned on a deserted island, and had to pick just one book, I'd probably have to go with Manning's JSF in Action by Kito Mann, with its comprehensive example and better than average writing (all the while trying to stuff Core JSF down my shirt.)

A number of these books cover advanced topics - and I'll review just that aspect in a later article.