Mastering JavaServer Faces 2 2 Leonard Anghel instant download
Mastering JavaServer Faces 2 2 Leonard Anghel instant download
download
https://textbookfull.com/product/mastering-javaserver-
faces-2-2-leonard-anghel/
https://textbookfull.com/product/javaserver-faces-introduction-
by-example-juneau-josh/
https://textbookfull.com/product/pro-hibernate-and-mongodb-the-
expert-s-voice-leonard-anghel/
https://textbookfull.com/product/the-definitive-guide-to-jsf-in-
java-ee-8-building-web-applications-with-javaserver-faces-bauke-
scholtz/
https://textbookfull.com/product/spring-boot-persistence-best-
practices-optimize-java-persistence-performance-in-spring-boot-
applications-1st-edition-anghel-leonard/
Java Coding Problems: Become an expert Java programmer
by solving over 200 brand-new, modern, real-world
problems, 2nd edition Anghel Leonard
https://textbookfull.com/product/java-coding-problems-become-an-
expert-java-programmer-by-solving-over-200-brand-new-modern-real-
world-problems-2nd-edition-anghel-leonard/
https://textbookfull.com/product/java-coding-problems-2nd-
edition-become-an-expert-java-programmer-by-solving-
over-200-brand-new-modern-real-world-problems-anghel-leonard/
https://textbookfull.com/product/mastering-embedded-linux-
programming-second-edition-unleash-the-full-potential-of-
embedded-linux-with-linux-4-9-and-yocto-project-2-2-morty-
updates-chris-simmonds/
https://textbookfull.com/product/mastering-pfsense-2-4-master-
the-art-of-managing-securing-and-monitoring-your-on-premises-and-
cloud-network-using-the-powerful-pfsense-2-4-3-zientara/
https://textbookfull.com/product/%eb%b9%84%ed%83%80%eb%af%bc-
%ed%95%9c%ea%b5%ad%ec%96%b4-2-vitamin-korean-2-1st-edition-cho-
jungsoon/
Mastering JavaServer
Faces 2.2
Anghel Leonard
BIRMINGHAM - MUMBAI
Mastering JavaServer Faces 2.2
All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information contained in this book is
sold without warranty, either expressed or implied. Neither the author, nor Packt
Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
ISBN 978-1-78217-646-6
www.packtpub.com
Graphics
Technical Editors Valentina Dsilva
Krishnaveni Haridas
Taabish Khan Production Coordinator
Pramod Kumavat Arvindkumar Gupta
Mukul Pawar
Siddhi Rane Cover Work
Arvindkumar Gupta
About the Author
Currently, Anghel is developing web applications using the latest Java technologies
on the market (EJB 3.0, CDI, Spring, JSF, Struts, Hibernate, and so on). Over the
past two years, he's focused on developing rich Internet applications for geographic
information systems.
About the Reviewers
Besides his work as a software developer, he also likes to write about JSF-related
techniques. In November 2009, his first book JavaServer Faces 2.0, dpunkt.verlag was
published, followed by the updated edition JavaServer Faces 2.2 in November 2013
by the same publisher.
Furthermore, he is responsible for the contents of the German online JSF tutorial
at http://jsfatwork.irian.at provided by Irian, and he also writes about
JSF-related techniques in his blog at http://jsflive.wordpress.com.
Michael has done technical reviewing for Java 8 in Action, Manning Publications Co.
Luca Preziati lives in Milan and has worked for six years as a Java consultant,
focusing the past five years on document management systems handling massive
volumes of data. In 2014, he joined GFT Italia full time. He has considerable
experience with both Alfresco and Documentum, as well as Liferay and Kettle.
In his free time, he enjoys swimming, biking, playing the guitar, and wine tasting
with his girlfriend.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub
files available? You can upgrade to the eBook version at www.PacktPub.com and as a print
book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
service@packtpub.com for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a
range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
TM
http://PacktLib.PacktPub.com
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book
library. Here, you can access, read, and search across Packt's entire library of books.
Why subscribe?
• Fully searchable across every book published by Packt
• Copy and paste, print, and bookmark content
• On demand and accessible via web browser
[ ii ]
Table of Contents
[ iii ]
Table of Contents
[ iv ]
Table of Contents
[v]
Table of Contents
[ vi ]
Table of Contents
[ vii ]
Preface
This book will cover all the important aspects (Big Ticket features) involved in
developing JSF 2.2 applications. It provides clear instructions for getting the most
out of JSF 2.2 and offers many exercises (more than 300 complete applications) to
build impressive JSF-based web applications.
We start off with a chapter about Expression Language (EL) and cover the
most important aspects of EL 2.2 and EL 3.0. We continue with a comprehensive
dissertation about communication in JSF, followed by an exciting chapter about
JSF 2.2 scopes. At this point, we bring into discussion most of the JSF artifacts and
configurations. Further, we start a suite of very interesting topics, such as HTML5
and AJAX. After that we dissect the JSF view state concept and learn how to deal
with this delicate JSF topic. Furthermore, we will discuss in detail about custom
components and composite components. After this, we will talk about library
contracts (themes) of JSF 2.2 resources. Finally, the last chapter will fortify your
knowledge about JSF 2.2 Facelets.
Chapter 3, JSF Scopes – Lifespan and Use in Managed Beans Communication, teaches you
to distinguish between the bad and good practices of using JSF and CDI scopes. We
will discuss JSF scopes versus CDI scopes, request, session, view scope (including the
new JSF 2.2 view scope), application, conversation scope, JSF 2.2 flow scope in detail
(Big Ticket feature), and more.
Chapter 4, JSF Configurations Using XML Files and Annotations – Part 1, depicts the
JSF artifact's configuration aspects in a learning-by-example fashion. Configuring
JSF artifacts in the faces-config.xml file is pretty straightforward and boring,
but if we take each artifact and exploit its potential in several use cases, then things
become much more interesting.
Chapter 5, JSF Configurations Using XML Files and Annotations – Part 2, acts as a
continuation of the previous chapter. Here, we will discuss configuring resource
handlers (JSF 2.2's new javax.faces.WEBAPP_RESOURCES_DIRECTORY context
parameter), configuring flash (JSF 2.2 FlashFactory, FlashWrapper, and flash
system events), JSF 2.2 Window ID API, the injection mechanism (which, starting
with JSF 2.2, is possible in most JSF artifacts), and more.
Chapter 6, Working with Tabular Data, pays tribute to the <h:dataTable> tag.
Here, we will focus on the JSF 2.2 CollectionDataModel API (which supports the
Collection interface in UIData). Moreover, we will learn about table pagination,
deleting/editing/updating table rows, filtering, and styling JSF tables.
Chapter 7, JSF and AJAX, exploits the JSF 2.2 delay attribute for queue control of
AJAX requests. It discusses how to reset value attributes using JSF 2.2 (input fields
can be updated with AJAX after a validation error), AJAX and JSF 2.2 flow scope,
how to customize AJAX script, and more. This is a classic chapter in almost any
JSF book.
Chapter 8, JSF 2.2 – HTML5 and Upload, divides the topic into two parts. The first part
is entirely dedicated to the Big Ticket feature, HTML5, and JSF 2.2 (pass-through
attributes and elements). The second part is dedicated to JSF 2.2's new upload
component, <h:inputFile>.
Chapter 9, JSF State Management, provides a detailed dissertation about the JSF view
state. The headings of this chapter will refer to JSF's saving view state (including
JSF 2.2 case insensitivity for state saving method and standardized server state
serialization) and JSF 2.2 stateless view (Big Ticket feature).
[2]
Preface
Chapter 11, JSF 2.2 Resource Library Contracts – Themes, dedicates itself to the new
JSF 2.2 Resource Library Contracts feature (Big Ticket feature). You will learn how
to work with contracts, style JSF tables and UI components using contracts, style
contracts across different kind of devices, and more.
Chapter 12, Facelets Templating, depicts the viral aspects of Facelets templating.
We will focus on the declarative and programmatical aspects of Facelets.
Appendix, The JSF Life Cycle, covers a diagram of the different JSF phases.
Conventions
In this book, you will find a number of styles of text that distinguish between
different kinds of information. Here are some examples of these styles, and an
explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions,
pathnames, dummy URLs, user input, and Twitter handles are shown as
follows: "For example, in the following example, you call a method named
firstLambdaAction—the lambda expression is invoked from this method."
[3]
Preface
When we wish to draw your attention to a particular part of a code block, the
relevant lines or items are set in bold:
<h:dataTable value="#{playersBean.dataArrayList}"
binding="#{table}" var="t">
New terms and important words are shown in bold. Words that you see on the
screen, in menus or dialog boxes for example, appear in the text like this: "When
the Login button is clicked, JSF will call the playerLogin method."
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about
this book—what you liked or may have disliked. Reader feedback is important for
us to develop titles that you really get the most out of.
If there is a topic that you have expertise in and you are interested in either writing
or contributing to a book, see our author guide on www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to
help you to get the most from your purchase.
[4]
Preface
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you find a mistake in one of our books—maybe a mistake in the text or
the code—we would be grateful if you would report this to us. By doing so, you can
save other readers from frustration and help us improve subsequent versions of this
book. If you find any errata, please report them by visiting http://www.packtpub.
com/submit-errata, selecting your book, clicking on the errata submission form link,
and entering the details of your errata. Once your errata are verified, your submission
will be accepted and the errata will be uploaded on our website, or added to any list of
existing errata, under the Errata section of that title. Any existing errata can be viewed
by selecting your title from http://www.packtpub.com/support.
Piracy
Piracy of copyright material on the Internet is an ongoing problem across all media.
At Packt, we take the protection of our copyright and licenses very seriously. If you
come across any illegal copies of our works, in any form, on the Internet, please
provide us with the location address or website name immediately so that we can
pursue a remedy.
We appreciate your help in protecting our authors, and our ability to bring you
valuable content.
Questions
You can contact us at questions@packtpub.com if you are having a problem with
any aspect of the book, and we will do our best to address it.
[5]
Dynamic Access to
JSF Application Data
through Expression
Language (EL 3.0)
Java Expression Language (EL) is a compact and powerful mechanism that enables
dynamic communication in JSP and JSF-based applications (including development
frameworks based on JSF such as PrimeFaces, ICEfaces, and RichFaces); we embed
expressions in the presentation layer to communicate with the application logic
layer. EL provides bidirectional communication, which means that we can expose
application logic data to the user, but we also can submit user data to be processes.
Generically speaking, EL can be used to populate HTTP requests with user data,
to extract and expose data from HTTP responses, to update HTML DOM, to
conditionally process data, and much more.
In this chapter, you will see how to use EL in web pages to communicate with
managed beans, which is the most common case in JSF applications. We will
cover the following topics:
EL syntax
In this section, you can see an overview of the main aspects of EL 2.2 and 3.0 syntax.
EL supports a handful of operators and reserved words. Each of these are quickly
described in the following section (more details are in the EL specification document
(http://download.oracle.com/otndocs/jcp/el-3_0-fr-eval-spec/index.html)).
EL operators
EL supports the following categories of operators—arithmetic, relational, logical,
conditional, empty and added starting with EL 3.0, string concatenation, assignment
and semicolon operators:
[8]
Chapter 1
EL precedence of operators
Conforming to EL specification, the precedence of operators from the highest to
lowest, left to right is as follows:
• [].
• () (used to change the precedence of operators)
• - (unary) not ! empty
• * / div % mod
• + - (binary)
• +=
• < > <= >= lt gt le ge
• == != eq ne
• && and
• || or
• ?:
• -> (lambda expression)
• =
• ;
EL reserved words
EL defines the following reserved words:
• and, or, not, eq, ne, lt, gt, le, ge, true (Boolean literal), false
(Boolean literal), null, instanceof (a Java keyword to do a class
comparison between objects), empty, div, and mod
[9]
Dynamic Access to JSF Application Data through Expression Language (EL 3.0)
Immediate evaluation returns the result as soon as the page is first rendered. These
kinds of expressions are read-only value expressions and they can be present only in
tags that accept runtime expressions. They are easy to recognize after the ${} notation.
Usually, they are used for arithmetic and logical operations in JSP pages.
Deferred evaluation can return the result at different phases of a page's life cycle
depending on the technology that is using the expression. JSF can evaluate the
expression at different phases of the life cycle (for example, during the rendering
and postback phase), depending on how the expression is being used in the page.
These kind of expressions can be value and method expressions, and they are
marked by the #{} notation.
EL value expressions
Value expressions are probably used the most, and they refer to objects and their
properties and attributes. Such expressions are dynamically used to evaluate results
or set bean properties at runtime. Through value expressions, you can easily access
JavaBeans components, collections, and Java SE enumerated types. Moreover, EL
provides a set of implicit objects that can be used to get attributes from different
scopes and parameter values. Furthermore, you will see how EL deals with each of
these objects.
Value expressions that can read data, but cannot write it are known
as rvalue (${} expressions are always rvalue), while those that can
read and write data are known as lvalue (#{} expressions can be
rvalue and/or lvalue).
[ 10 ]
Chapter 1
@Named(value = "myPlayersBean")
//some scope
public class PlayersBean{
...
}
Now, for the first two examples, EL refers to the PlayersBean managed bean, like
this—the name is obtained from taking the unqualified class name portion of the
fully qualified class name and converting the first character to lowercase as follows:
#{playersBean}
In addition, for the next two examples, EL uses the explicit name as follows:
#{myPlayersBean}
You should use CDI beans whenever possible since they are
more flexible than JSF managed beans, and because annotations
from javax.faces.bean will be deprecated in a future JSF
version. Therefore, the CDI ones are recommended.
[ 11 ]
Dynamic Access to JSF Application Data through Expression Language (EL 3.0)
When the referenced managed bean cannot be found in any scope, a null value will
be returned.
EL expressions that can access these properties contain the dot or square brackets
notation, []. For example, let's suppose that the PlayersBean managed bean
contains two fields defined like the following lines:
private String playerName = "Rafael";
private String playerSurname = "Nadal";
EL can access these fields through their getter methods; therefore, you need to define
them as shown in the following code:
public String getPlayerName() {
return playerName;
}
public String getPlayerSurname() {
return playerSurname;
}
Now, an expression that accesses the playerName property can use the dot
notation (.) to refer it, as shown in the following line of code:
#{playersBean.playerName}
Alternatively, this expression can use the square brackets notation, [], as shown in
the following line of code:
#{playersBean['playerName']}
[ 12 ]
Random documents with unrelated
content Scribd suggests to you:
Atlas. Here lies such a gentleman, sir, whose
clothes (were they not greasy) would bespeak
him so.
Light. Then I pray, sir, when your leisure shall
permit, that you would vouchsafe to help me to
the speech of him.
Atlas. We must first crave your oath, sir, that
you come not with intent to molest, perturb, or
endanger him; for he is a gentleman, whom it
hath pleased fortune to make her tennis-ball of,
and therefore subject to be struck by every fool
into hazard.
Light. In that I commend thy care of him, for
which friendship here's a slight reward; tell him
a countryman of his, one Lightfoot, is here,
and[364] [he] will not any way despair of his
safety.
Atlas. With all respect, sir; pray, command my
house.
[Exit Atlas.
Enter Carracus.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com