For your convenience Apress has placed some of the front
matter material after the index. Please use the Bookmarks
and Contents at a Glance links to access them.
Download from Wow! eBook <www.wowebook.com>
v
Contents at a Glance
About the Authors ��������������������������������������������������������������������������������������������������������������xiii
About the Technical Reviewer �������������������������������������������������������������������������������������������� xv
Introduction ���������������������������������������������������������������������������������������������������������������������� xvii
Chapter 1: JSF Introduction ■ ����������������������������������������������������������������������������������������������1
Chapter 2: JSF Under the Hood—Part 1 ■ ��������������������������������������������������������������������������29
Chapter 3: JSF Under the Hood—Part 2 ■ ��������������������������������������������������������������������������63
Chapter 4: JSF Under the Hood—Part 3 ■ ��������������������������������������������������������������������������93
Chapter 5: JSF 2�2: What’s New? ■ �����������������������������������������������������������������������������������123
Chapter 6: Going Deep: JSF Custom Components ■ ���������������������������������������������������������145
Chapter 7: Basic JSF2 HTML5 Components ■ �������������������������������������������������������������������167
Chapter 8: Advanced JSF2 HTML5 Components ■ ������������������������������������������������������������191
Chapter 9: JSF Component Libraries ■ �����������������������������������������������������������������������������215
Chapter 10: Creating a Basic JSF 2�2 Application ■ ���������������������������������������������������������241
Chapter 11: JSF2 Advanced Topics ■ �������������������������������������������������������������������������������267
Chapter 12: JSF2 Security and Performance ■ �����������������������������������������������������������������289
Chapter 13: Applying It All: The Mega App ■ ��������������������������������������������������������������������307
Index ���������������������������������������������������������������������������������������������������������������������������������385
xvii
Introduction
is book is an ideal resource for Java developers intending to build sophisticated, enterprise-grade web experiences
with HTML5-enabled JSF. Java web developers today have an unprecedented variety of libraries, frameworks,
and components available for creating rich and meaningful applications. e result is an ecosystem that delivers
incredible productivity at an individual level.
at being said, most software is built in team environments with shared code bases, multiple service endpoints,
complex views, and diverse functional areas. A multitude of choices can end up being counterproductive in team
environments, resulting in the accrual of technical debt and multiple implementation patterns for similar use-cases.
Component-based frameworks like JavaServer Faces (JSF) are designed to curb such behavior in team environments,
while still giving developers latitude to customize when a use-case requires it.
In Pro JSF and HTML5 we show you how to leverage the full potential of JSF, a server-side component-oriented
Java web framework that sets the standard for developer team productivity. It oers developers a rich array of
standard and third-party interface components that can be used to compose complex views in an intuitive, reusable,
and repeatable way. e latest standard, JSF 2.2, allows HTML5-enabled components to be used in the composition
of views. We demonstrate how a developer can couple the power and expressivity of HTML5 with the discipline and
repeatability of JSF components to deliver rich user experiences.
is book provides solid coverage for foundational and advanced topics of JavaServer Faces (especially JSF 2.2).
e rst four chapters cover the JSF life cycle, architecture, managed beans and integration with CDI (Context and
Dependency Injection), expression language, exception handling, conversion and validation, JSF events (Faces events,
Phase events, and System events), and view parameters. Chapter 5 covers the new features of JSF 2.2, such as faces
ow, resource library contracts, HTML5 friendly markup, and Ajax le uploading.
Chapters 6, 7, and 8 detail the process of creating HTML5-enabled components in the JSF 2.2 world with a number
of interactive examples. Chapter 9 covers the basics of two popular JSF component libraries (PrimeFaces and
RichFaces) with two interactive examples.
In Chapter 10, a basic JSF 2.2 application is developed that utilizes Java EE 7 technologies (CDI, JPA 2.1, and EJB 3.2)
in order to facilitate bean management, transaction management, and persistence in the JSF application. Chapter 11
covers JSF advanced topics such as application design considerations, unit testing, and Ajax queuing.
Chapter 12 covers important topics relating to JSF application security including authentication, authorization,
and data protection. e chapter shows how to apply container-managed security in an example application.
Chapter 12 also covers JSF performance considerations to help ensure that your applications run smoothly and
responsively.
Finally, Chapter 13 gathers most of the topics covered in the book and puts them into practice in the form of an
advanced application that implements real-world use-cases.
We want this book to serve as a progressive guide to the component-oriented framework beginner, and as a
reference for the seasoned JSF developer who is looking to maximize JSF 2.2’s signicantly upgraded capabilities.
We wish you happy reading and productive coding!
1
Chapter 1
JSF Introduction
This chapter will explain what the JavaServer Faces (JSF) framework is, how the framework evolved over time, key
aspects of its architecture, and details about its signature request processing life cycle. Beyond explanations, we’ll go
hands-on and guide you through your first JSF application from scratch using JSF 2.1 and Maven 3; you will learn how
to deploy your JSF 2.1 application on two different web containers (GlassFish and Tomcat). If you are already familiar
with JSF at a basic component level, a deeper understanding of the request life cycle will serve you well when tasked
with more complex applications.
What Is JSF?
JSF is a server-side component-oriented Java web framework that simplifies the process of developing rich Java
enterprise web applications. JSF excels at delivering a highly customizable yet standardized approach to building
application user interfaces. The user interface tier is usually the most challenging and variable part of any application.
It is also the difference between a successful application that is widely adopted and evolved consistently versus one
that is reluctantly adopted and frequently changed to meet user desires.
JSF provides a powerful platform for solving the common problems that frequently appear during Java enterprise
web application development, such as validation, conversion, navigation, templating, and page flows. Providing a
standard way for resolving the common problems of web application development makes JSF an excellent framework
that reduces the development and maintenance time of web applications.
This is especially true when your development team is large and distributed, a common scenario encountered
in the enterprise. Building user experiences around a set of standardized JSF components allows for a fair degree of
customization and expression, but also establishes a “shared DNA” for how an application should look, behave, and
respond across different implementations.
JSF offers APIs and tag libraries for
Providing UI components for rapid development of applications.•
Wiring component events into Java server-side code.•
Binding UI components with POJOs (Plain Old Java Objects).•
Providing a set of useful built-in validators and converters, and offering a mechanism for •
creating custom ones in order to fulfill specific requirements.
Handling exceptions.•
Handling navigation between application pages.•
Creating page templates and application templates.•
Defining page flows in a manner that reflects application requirements.•