Free Sample
+ Collection

JSF 2.0 Cookbook

Anghel Leonard

Over 100 simple but incredibly effective recipes for taking control of your JSF applications
RRP $26.99
RRP $44.99
Print + eBook

Want this title & more?

$12.99 p/month

Subscribe to PacktLib

Enjoy full and instant access to over 2000 books and videos – you’ll find everything you need to stay ahead of the curve and make sure you can always get the job done.

Book Details

ISBN 139781847199522
Paperback396 pages

About This Book


  • Discover JSF 2.0 features through complete examples
  • Put in action important JSF frameworks, such as Apache MyFaces Core, Trinidad, Tomahawk, RichFaces Core, Sandbox and so on
  • Develop JSF projects under NetBeans/Glassfish v3 Prelude and Eclipse/JBoss AS
  • Part of Packt's Cookbook series: Each recipe is a carefully organized sequence of instructions to complete the task as efficiently as possible

Who This Book Is For

This book is for two types of audience:

  • Newcomers who know the basics of JSF but are yet to develop real JSF applications.
  • JSF developers who have previous experience but are lacking best practices and a standard way of implementing functionality

Table of Contents

Chapter 1: Using Standard and Custom Converters in JSF
Working with implicit and explicit conversions
Standard converters for numbers
Standard converters for date and time
Converters and NULL values
Creating and using a custom converter
Using custom converters for h:selectOneMenu
Binding converters to backing bean properties
RichFaces and standard converters
RichFaces and custom converters
Instance variables in converters
Client-side converters with MyFaces Trinidad
Chapter 2: Using Standard and Custom Validators in JSF
Using a standard validator
Getting ready
How to do it...
How it works...
See also
Customizing error messages for validators
Creating a custom validator
Binding validators to backing bean properties
Validating forms with RichFaces rich:beanValidator
Validating forms with RichFaces rich:ajaxValidator
Apache MyFaces Commons validators
Bean validation with f:validateBean
Enforcing a value's presence with f:validateRequired
Using regular expressions with f:validateRegex
Chapter 3: File Management
Downloading files using Mojarra Scales
Multi-file upload using Mojarra Scales
File upload with Apache MyFaces Tomahawk
AJAX multi-file upload with RichFaces
Downloading with PrimeFaces 2.0
PPR multi-file upload with PrimeFaces 2.0
Extracting data from an uploaded CSV file
Exporting data to Excel, PDF, CVS, and XML
Chapter 4: Security
Working with the JSF Security project
Using the JSF Security project without JAAS Roles
Using secured managed beans with JSF Security
Using Acegi/Spring security in JSF applications
Chapter 5: Custom Components
Building a "HelloWorld" JSF custom component
Renderers/validators for custom components
Adding AJAX support to JSF custom components
Using Proxy Id library for dynamic IDs
Using JSF ID Generator
Accessing resources from custom components
Custom components with Archetypes for Maven
RichFaces CDK and custom components
Composite custom components with zero Java
Creating a login composite component in JSF 2.0
Building a spinner composite component in JSF 2.0
Mixing JSF and Dojo widget for custom components
Chapter 6: AJAX in JSF
A first JSF 2.0-AJAX example
Using the f:ajax tag
Installing and using Dynamic Faces in NetBeans 6.8
Using the inputSuggestAjax component
ajax4jsf—more than 100 AJAX components
Writing reusable AJAX components in JSF 2.0
PrimeFaces, CommandLink, and CommandButton
Chapter 7: Internationalization and Localization
Loading message resource bundles in JSF
Using locales and message resource bundles
Message resource bundles without f:loadBundle
Working with parameterized messages
Accessing message resource keys from a class
Providing a theme to a Visual Web JSF Project
Displaying Arabic, Chinese, Russian, and so on
Selecting a time zone in JSF 2.0
Chapter 8: JSF, Images, CSS, and JS
Injecting CSS in JSF
JSF, CSS, and tables
JSF and dynamic CSS
Integrating JavaScript and JSF
Getting a JSF inputText value from JavaScript
Working with JSF hidden fields from JavaScript
Passing parameters from JS to JSF (client to server)
Passing parameters from JSF to JS (server to client)
Opening a pop-up window using JSF and JS
Passing parameters with HTTP GET within the URL
Communication between parent pop-up windows
Populating a JS load function with JSF values
Dynamic images with PrimeFaces
Cropping images with PrimeFaces
Working with rss4jsf project
Using resource handlers
Chapter 9: JSF—Managing and Testing
Managing JSF with Faces Console
Testing JSF applications with JSFUnit
JSFUnit and Ant
A JSF and JMeter issue
Working with JSF Chart Creator
Chapter 10: Facelets
Installing Facelets under JSF 1.2 (or JSF 1.1)
Facelets aliasing components
Facelets templating
Creating composition components in JSF 2.0
Passing sub-elements to composition components
Passing actions to composition components
Chapter 11: JSF 2.0 Features
JSF 2.0 annotations
The JSF 2.0 exception handling mechanism
Bookmarking JSF pages with PrettyFaces
JSF declarative event handling
URLs based on specified navigation outcome
JSF view parameters
JSF 2 and navigation cases
Chapter 12: Mixing JSF with Other Technologies
Configuring Seam with JSF
An overview of Seam JSF controls
Mixing JSF and JSTL
Integrating JSF and Hibernate
Integrating JSF and Spring
Mixing JSF and EJB (JPA)

What You Will Learn


  • Explore all the new features of JSF 2.0 that has numerous advantages over JSF 1.2
  • Work with standard and custom JSF converters and validators
  • Learn to upload and download with JSF, RichFaces and MyFaces
  • Work with resources such as CSS, JavaScript and images
  • Develop sophisticated applications using standard and custom components
  • Explore AJAX in JSF and related frameworks
  • Enhance your applications with internationalization and localization
  • Exploit all of the security tasks in JSF and perform thorough testing of your applications
  • Get to grips with JSFUnit, JMeter and JXIsight
  • Integrate JSF with JSTL, Spring and Hibernate

In Detail

JavaServer Faces is a Java-based Web application framework intended to simplify development of user interfaces for Java EE applications. You may already be aware of the laborious search through reference guides and documentation to develop your JSF applications. With the JSF Cookbook, you can find solutions to the most common JSF problems in a quick and easy way.

This book will cover all the important aspects involved in developing JSF applications. It provides clear instructions for getting the most out of JSF and offers many exercises to build impressive desktop-style interfaces for your web applications. Develop JSF applications starting with simple recipes and gradually moving on to complex recipes.

We discuss all of the fundamental aspects of JSF applications. Once you locate your desired topic, you can try to find a recipe that corresponds to your problem.

We start off with the simple concepts of Converters, validators and file management. We then work our way with various resources such as CSS, JavaScript, and images to improve your web applications. You will learn to build simple and complex custom components to suit your needs. Next, you get to exploit AJAX as well as implement internationalization and localization for your JSF applications. We then look into ensuring security for your applications and perform testing of your applications. You also get to learn all about Facelets and explore the newest JSF 2.0 features. Finally you get learn a few integrations such as JSTL with JSF, Spring with JSF, and Hibernate with JSF. All these concepts are presented in the form of easy-to-follow recipes.

Each chapter discusses separate types of recipes and they are presented with an increasing level of complexity from simple to advanced. All of these recipes can be used with JSF 1.2 as well.


Read More