JSF 2.0 Cookbook - book review

This is a review of "JSF 2.0 Cookbok" book by Anghel Leonard (Packt Pub, 2010).

Introduction

I used to develop frontends of web applications some time ago using different frameworks and templates (mainly JSP 2, Velocity and FreeMarker). Since then a lot has changed in frontend frameworks and I wanted to get an idea what is the status of JSF nowadays. And thus I checked the “JSF 2.0 Cookbook” by Anghel Leonard.

Chapters

The book is divided into 12 chapters devoted to different areas of web development (e.g. validation, i18n, security etc.). Each chapter contains a short introductory material that sometimes gives a very brief information on the content of this chapter and sometimes explains how JSF handles this area of issues. Then comes a bunch of recipes. The source code for every chapter can be downloaded form Packt’s site.
There is also one appendix which gives advices on integration of JSF with other technologies.

Recipes

Each recipe can be read and applied individually (in some cases it is assumed that reader understood few previous recipes). Each one contains all information required to run them. This is very handy if you don’t intend to read the book but only to pick up the bits that you are interested in (which is exactly what you would expect a cookbook to be).
The recipes cover many typical issues that almost every web based project needs to implement. How to export data as XLS or CSV file and how to upload many files at once. How to validate input data with regexp. How to provide i18n features. How to go create custom components when you have some specific requirements that are not met by existing components. And many other similar things are explained.
The recipes are clear and accompanied by code snippets. In general I think I would have no problems to implement the discussed solutions (but I admit that I’ve never tried to do that!). However in some cases (e.g. security chapter) I think much more knowledge is required to fully understand and reuse recipes than the book offers.

JSF & Co.

Many recipes are devoted to various JSF component libraries (Apache MyFaces, JBoss RichFaces, Mojarra Scales) or cooperation of JSF with other frameworks (ajax4jsf, Spring Security). I think that is ok, because nowadays integration of various tools is very common. It was also interesting to me, because this way I learned about many projects that I never heard of.
What surprised me was that sometimes there is more than one recipe for the same problem. For example there is a recipe for “Downloading files using Mojarra Scales” and “Download with Prime Faces”. One the one hand this is valuable - no matter which framework you use, you’ll find something for your needs. On the other hand this means that some recipes are completely useless for you (because they present solutions using different frameworks than you do).

Nitpicking

I didn’t like few things that I found in code snippets, and I wouldn’t recommend to learn Java coding based on this code:

  • use of setters in situations when constructor parameters and final fields would have been much more appropriate,
  • use of String where custom type should be created,
  • use of iterators instead of for-each loop,
  • hardcoded paths to files,
  • bad exception handling (i.e. catch (NumberFormatException e) { throw new NumberFormatException(e.getMessage()); })
  • some code snippets might be shorter (e.g. by removing useless comments, import statements or getters/setters methods),
  • some code snippets could be omitted at all (i.e. some Maven poms),
  • the most important code parts are not highlighted.

All of the above issues are minor and do not lower the good overall impression.

Conclusion

To sum it all up I read the book with real interest. I have learned about many JSF-related technologies and got a good understanding of what JSF (& Co.) can offer to me. I think that some of the recipes presented in the book would shorten very much my development if I were to dive in JSF world. Other would given me valuable pointers on what and where to look for.
I also found with delight that nowadays there are many “out-of-the-box” solutions to the problems that few years ago I had to solve myself. :)

Links

 
 
 
This used to be my blog. I moved to http://tomek.kaczanowscy.pl long time ago.

 
 
 

Please comment using