Last July, I was asked to review JSF 2.0 Cookbook by Anghel Leonard. I finally found time to finish reading the book and wrote a review. (If you are interested, back in April I reviewed another book from Packt Publishing: JSF 1.2 Components.)
Chapter 1 – Using Standard and Custom Converters in JSF
The chapter covers how to use standard converters and how to build custom converters. The author does a good job covering the standard out-of-the-box converters with a number of examples. The chapter then shows how to create your own custom converter. There are a number of small typos, but that’s not a big deal. Although standard and custom converters are covered in regular JSF books, it’s a topic that many people have difficulties with so I think there is a place for them in a recipe-type book. Two other things I found useful are discussions of RichFaces build-in converters and MyFaces converters.
Chapter 2 – Using Standard and Custom Validators in JSF
Similar to chapter 1, chapter 2 covers how to use standard validators and how to build custom validators. There are good examples such as how to overwrite default validation error messages. The chapter also covers RichFaces’ rich:beanValidator and rich:ajaxValidator, which work with Hibernate Validator. MyFaces Commons validators are covered as well. The chapter ends with coverage of new validation features in JSF 2 such as f:validateBean, f:validateRequired, and f:validateRegex.
Chapter 3 – File Management
This chapter covers file management – more specifically, file upload and download. It’s a good chapter with good examples and tips. (How- to on use file uploading is usually a frequently asked question on various JSF forums.)
Chapter 4 – Security
The chapter covers securing JSF applications. The chapter covers four different recipes or examples for securing a JSF application. Each of the four recipes uses a different framework/approach: working with the JSF Security project, using the JSF Security project without JAAS Roles, using secured managed beans with JSF Security, and Using Acegi/Spring security in JSF applications. It’s a good chapter. JSF developers often ask how to secure a JSF application and I believe this chapter provides good coverage of this topic.
Chapter 5 – Custom Components
The chapters starts with showing how to build a simple “Hello World” custom component. How to build custom JSF components is always a very popular topic and probably an entire book can be dedicated to just that. This simple example does a good job showing what goes into build a custom JSF component, I just wouldn’t use JSP as the view. The chapter continues with adding Ajax to a custom component and accessing resources. RichFaces CDK (Component Development Kit) is covered briefly as well. Towards the end, the chapters covers composite custom components which is a JSF 2 feature.
Chapter 6 – AJAX in JSF
The chapter covers Ajax and starts with new Ajax support in JSF 2. I liked that the first example showed how to use JSF 2 Ajax in programmatic way followed by the second example showing how to use f:ajax tag (for the same application). At the same time I was disappointed that the example was very basic (a button that generates a random number). I think I would prefer to see a more advanced or interesting usage.
Next example or recipe is using Dynamic Faces example. I’m not sure why Dynamic Faces extension was mentioned in the book, it looks like the last time this extension was updated was in 2006. There is also quick mention and screen shot of Woodstock component library. This library has been folded in IceFaces long time ago.
Next section covers RichFaces a4j:support tag. I think there is still some confusion out there, some believe ajax4jsf is a separate library (it was long time ago). ajax4jsf (or a4j) is just a tag library inside RichFaces, it’s not a separate library. The author mentions that a4j:support is available in RichFaces since 3.0. a4j:support tag was available even before RichFaces as part of Ajax4jsf project (at that point it was a separate project). This blog post describes Ajax4jsf and RichFaces history.
The next section covers Writing resuable Ajax component followed by a short section on PrimeFaces command link and command button controls. The PrimeFaces example is nice but also rather trivial in my opinion.
Chapter 7 – Internationalization and Localization
Chapter 7 covers Internationalization and Localization. The chapters provides good coverage and examples.
Chapter 8 – JSF, Images, CSS, and JS
Chapter 9 – Managing and Testing
This chapters covers Managing and Testing and this is where I had the biggest surprised. The book covers one of the first JSF GUI tools called Faces Console. The problem is that the tool hasn’t been updated since 2004 and can only create JSF configuration files version 1.0 or 1.1. I’m not clear why a book on JSF 2 covers such an old tool. The rest of the chapter is better. It covers testing JSF applications with JUnit. It’s a popular topic and often asked on forums. The chapter end with inserting charts into a JSF page based on JFreeChart.
Chapter 10 – Facelets
Chapter 10 is a very good chapter which covers Facelets and its features.
Chapter 11 – JSF 2.0 Features
Chapter 11 is dedicated to JSF 2 features and includes examples which cover annotations, bookmarking, declarative event handling, navigation and view params.
Chapter 12 – Mixing JSF with Other Technologies
The last chapters talks about how to use JSF with other technologies such as Seam, Hibernate, Spring, and EJB. The chapter doesn’t show any real recipes or examples but just a very high level and brief overview of what other technologies could be used with JSF. I guess that’s fine as these technologies are outside the scope of the book.
Appendix – Configuring JSF-related Technologies
Finally the appendix shows how to configure (web.xml) various libraries and extensions used in this book.
Did I like the book? Yes, the book is good and loaded with useful recipes and code examples. However, the book doesn’t replace a regular book on JSF such as JSF 2, The Complete Reference. If you have been using JSF, then this book is a good next step. If you are a newbie, I’d recommend reading a regular JSF book first. Many recipes can be used with JSF 1.2 as they don’t use any special features from JSF 2, so that’s good. There are a just a number of things I would change. A number of examples mention JSP, with Facelets now included in JSF 2, I’m not sure if it really makes sense to cover JSP. Most JSF 1.2 project also use Facelets today. I just wouldn’t cover an old tool such as Faces Console as it hasn’t been updated since 2004. They are much better tools out today such as JBoss Tools with very good JSF 1.2 and 2 support. Libraries such as Dynamic Faces and Woodstock have also faded away long time ago.
But as I said before, it’s a great book, and a great resource for the JSF community.
Happy New Year.