Faces in Action Marty Hall hallcoreservletscom coreservletscom Customized Java EE and JavaScript Training Agenda S ummary of evolving specs Java Web Apps in Java JSF 22 Summary of new features ID: 622263
Download Presentation The PPT/PDF document "JavaServer" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
JavaServer Faces in Action
Marty Hall, hall@coreservlets.com
coreservlets.com
Customized Java EE and JavaScript TrainingSlide2
Agenda
S
ummary of evolving specs
Java
Web Apps in Java
JSF 2.2
Summary of new features
One highly touted feature that really is great (with code and demo)
One highly touted feature that is not as great as it
sounds (with code and demo)
JSF 2.3
Summary of new features
One highly touted
feature
that really is great (with code and demo)
One supposed downside that may be a blessing in
disguise (with code and demo)
My favorite Web stack (and why)
JSF 2.3 (or 2.2),
PrimeFaces
, Java 8Slide3
Evolving SpecsSlide4
Java SE Versions
Version
My Take
Features
Early Java versions
Good at the time.
Too low
level by today’s standards.
Basis for Java language
Java 5
Yay!
Major update. Generics,
varargs
,
printf
,
@Override, new “for” loop.
Java 6
Yawn.
Minor update. Updates to collections, Swing, etc.
Java 7
Ho hum. On second thought, not bad.
Medium update. Fork/join framework, diamond operator, Strings in switch statements, try-with-resources, updates to Swing (esp. new look and feel).
Java 8
Yay! Yay!
Major update. Lambdas for functional programming. Streams for bulk operations.Slide5
Web Apps in Java
Version
My Take
Features
Servlets
and JSP
Good at the time.
Too low
level by today’s standards.
Servlets are foundation
for
most Java-based Web app frameworks.
JSP now mostly obsolete.
JSF 1
Boo!
Years after Struts and that is all we get?
Saving
grace: component framework paved the way for third-party libraries like
RichFaces
,
IceFaces
,
PrimeFaces
, etc.
JSF 2.0
Yay! Yay!
Facelets
instead of JSP. Annotations. Ajax support. Composite component framework. More smart defaults. Support for GET.
JSF 2.1
Yawn.
Small fixes and improvements.
JSF 2.2
Yay!
Faces flow. HTML
5 pass-through attributes.
Stateless views.
JSF 2.3
Yay.
Several
small but useful improvements.
Better support for looping and tables. Slide6
References
What’s new in JSF 2.2
http://jdevelopment.nl/jsf-22
/
What’s new in JSF 2.3
http://
jdevelopment.nl/jsf-23/
What’s new in Java 8
http://openjdk.java.net/projects/jdk8/features
http://www.coreservlets.com/java-8-tutorial
/
Download JSF 2.2 and 2.3
https://maven.java.net/content/repositories/releases/org/glassfish/javax.faces/Slide7
New Features of JSF 2.2 and 2.3Slide8
New Features in JSF 2.2
Faces flow
Pages can be grouped into chunks, each with their own beans and navigation
HTML 5 pass-through attributes
You can use placeholder, type="date", data-blah, etc.
Stateless views
No server-side, not client-side. No state saved at all.
View actions
Similar to normal action methods, but invoked on GET instead of POST
Ajax improvements
Queue control. Ajax-based file upload component.
Resource library contracts
Can specify prefix for folders that contain resources. Supports primitive skinning.
Programmatic configuration
Java calls in addition to annotations or faces-config.xml.Slide9
New Features in JSF 2.3 (Tentative)
More options for
UIRepeat
and
UIData
Iterable
, Map, custom data types
Java 8 is required
Java 7 code will still run (of course), but server must be running Java 8
Injection of JSF artifacts (major data structures)
Simpler to access artifacts from Java instead of from EL
@
SessionMap
, @
FlowMap
, @
HeaderMap
, @
RequestCookieMap
, etc.
Generic types
For
ExternalContext#getInitParamterMap
and Converter/Validator
interfacesSlide10
My Take
JSF 2.2: Faces Flow
Highly touted feature
Really great
JSF 2.2:
Passthrough
attributes for HTML 5
Highly touted feature
Not really so great
JSF 2.3: Better support for looping and data tables
Seems relatively minor
But very useful (and long overdue)
JSF 2.3: required to use Java 8
Seen by some as an intrusive restriction
Perhaps a blessing in disguiseSlide11
JSF 2.2 –Faces FlowSlide12
Big Ideas
Flows are groups of pages
Can enter flow at only a single place (start page)
Once inside, can navigate among any pages in flow
Can leave flow to one or more predefined outside pages
Can also have nested flows
Flows use flow-scoped beans
Wider scope than view scope: bean lives for same user in all pages in flow
Narrower scope than session scope: when user navigates outside flow, bean is removed from session and made available for garbage collection
There is also a new flowScope EL variable
Note: only quick summary and example here
Details and
extended examples at http://www.coreservlets.com/JSF-Tutorial/jsf2/Slide13
Motivation for Basic Flows
Modularity
Pages and beans can be self contained
Wizard-like structures
Fits well with a common approach to many Web activities. Like a method call:
A well
defined entry point, list of parameters, and return value.
A scope
, allowing information to be available only during the invocation of the
flow
and to not consume resources once the flow returns.
The ability to call
other flows before
returning
Less server memory
Vs. session scope, beans are removed from memory sooner: when user leaves flow
Not fooled by multiple browser tabs or windows
Each tab or window is considered to be a separate flow, in contrast to session scope, which is easily confused by multiple tabs or windowsSlide14
Motivation for Nested Flows
Modularity
Chopping self-contained part of into separate flow makes each piece easier to understand than one large flow
Reuse
More than one flow can use the same nested flow
For example, two different shopping flows could use the same checkout flow
The calling flow just passes in the starting data
Each of the shopping flows might pass in the list of items to be purchased
The calling flow can get back a result
The checkout flow could return a confirmation saying whether the transaction succeeded, failed, or was canceled by the user
14Slide15
Flow Scope
Flow-scoped beans: bigger scope than view-scoped beans
Available to the same user in all pages in a flow, rather than for a single page
Flow-scoped
beans: smaller scope
than
session-scoped
beans
The beans go away when user navigates out of flow
There is a new EL flowScope variable
That can be used to directly store simple values
But, flow-scoped beans are usually better
Flow-scoped beans depend on CDI
They require a Java EE 7 server or CDI to be added
You must use @Named, not @
ManagedBeanSlide16
Simplest Usage: Flow Conventions
You use folder that matches flow name
yourFlowName
/
Folder contains empty XML file
yourFlowName
/yourFlowName-flow.xml
Default start page matches flow name
yourFlowName
/
yourFlowName.xhtml
Other pages in flow have arbitrary names
yourFlowName
/
anything.xhtml
These are accessible only from within flow
Exit (return) page uses flow name
yourFlowName-return.xhtml
This is
not
in the
yourFlowName
folderSlide17
Quick Example Using Conventions
Walk through code
Folder/file structure
Flow-scoped bean
Forms
Demo
Navigation
Behavior of flow-scoped beanSlide18
Configuration in XML: Quick Summary
Basic flows (usually in
flowname
-flow.xml)
Define the start page
<start-node>
startPage
</start-node>
<view id="
startPage
">…</view>
Define the return page(s) (required)
<flow-return id="some-id">…</flow-return>
Map outcomes to pages
<view id="another-id">…</view>
Nested flows
One flow can invoke another
Calling flow uses <flow-call> in the XML configuration
file
The nested flow returns only to calling flow
The <flow-return> of nested flow refers to a page of the calling
flow
Calling flow can pass data to nested flow
Calling flow stores data with <outbound-parameter>
Nested flow receives data with <inbound-parameter
>Slide19
Configuration in Java
Setup
Register
a Java class and method
using several
standard
annotations
The annotated method
takes a
FlowBuilder
Basic flows
Define pages with
builder.viewNode
(…)
Define
start page with
builder.viewNode
(…).
markAsStartNode
()
Define return pages with
builder.returnNode
(…)
Nested flows
Calling a nested flow and passing
outbound parameters
builder.flowCallNode
("triggering-outcome
").
flowReference
("", "id-of-nested-flow")
.
outboundParameter
("
paramForNestedFlow
",
"#{
callingBean.property1}");
Receiving inbound parameters
builder.inboundParameter
("
paramForNestedFlow
",
"#{
nestedBean.property2}");Slide20
JSF 2.2 –HTML 5 Passthrough
AttributesSlide21
Overview
Idea
Can send arbitrary attributes directly to underlying HTML elements
Motivation
Make use of HTML 5 capabilities
The placeholder attribute
The data-
blah
attributes
The new input types (type="date
"
, type=
"
number
"
, type=
"
range
"
, type=
"
color
"
, etc.)
Syntax
Define namespace
xmlns:
h5="http://xmlns.jcp.org/
jsf
/
passthrough
"
Use
passthrough
attribute
<
h:inputText
…
h5:placeholder
="Enter text here"/>Slide22
My Take: Yawn
Placeholder text
Rich component libraries as good or better
All major libraries (
PrimeFaces
,
RichFaces
, etc.) have long supported this
Some revert to JavaScript if HTML 5 placeholder attribute not supported
data-
blah
attributes
Rich component libraries do not help with this, and it is good idea
But, this is not very common in JSF applications
And, jQuery deals with CSS class names more easily
New input types
Rich component libraries
much
better
Consistent support across browsers
Can apply skinning (theming)Slide23
Code Walkthrough and Demo
HTML 5 attributes
Placeholder text
Date input
PrimeFaces
Placeholder text
Date
inputSlide24
JSF 2.3 –Better Support for Looping and Data TablesSlide25
Overview: UIRepeat Support
Through JSF 2.2
List
Array
DataModel
ResultSet
(boo!)
null, single object
Added in JSF 2.3
Iterable
A
nd thus Collection automatically
Map
With automatic .key and .value properties
Custom type
Using annotation to specify a wrapper
DataModelSlide26
Code Walkthrough and Demo
Looping
With Collection (which extends
Iterable
)
With MapSlide27
JSF 2.3 –Requirement to Use Java 8Slide28
Overview
JSF 2.3 uses Java 8 internally
Since JSF will be part of Java EE 8
So JSF requires Java 8
Even if you just use the JSF JAR
Many (most?) commercial JSF applications still run on Java 7
Because the commercial server they use is not certified on Java 8
Because they don’t want to make the effort to upgrade
A blessing in disguise?
They should be on Java 8
now
anyhow
Transitioning is not as hard as they think
Benefits of Java 8 are much larger than they think
Hearing about JSF 2.3 now will give them nudge to move to Java 8
earlierSlide29
Code Walkthrough and Demo
Simple String filtering in Java 8
Used in
autocompleter
Java 8 version simpler, more flexible, more efficientSlide30
My Favorite Web StackSlide31
Recent Trend
Simpler server environment (e.g., Spring MVC)
Mostly provider of JSON Web Services
Not so much a page-layout engine
More explicit JavaScript on the client
(e.g., jQuery and jQuery UI)
More control
More workSlide32
Job PostingsSlide33
Google SearchesSlide34
Job PostingsSlide35
Google SearchesSlide36
My Take
JSF with
PrimeFaces
Much
simpler
M
ore productive
Spring MVC with jQuery
Better separation
Front end not tied to language used on back end (and vice versa)
Slightly more control
on the client side (e.g., pure client-side form validation
)
Java 8
Big win for either approach
My personal favorite
JSF 2.3
PrimeFaces
Java 8Slide37
Wrap-UpSlide38
Summary
JSF 2.2
Major upgrade with several important new features
Faces flow is one: very valuable
HTML 5
passthrough
attributes is another: not so valuable
JSF 2.3
Relatively minor upgrade, but with some useful features and with a requirement to use Java 8
Better
UIRepeat
/
UIData
support is one: convenient and long overdue
Java 8 “restriction” is not so onerous: maybe a good thing
Java 8
Big win for everyone
My favorite combo
JSF 2.3,
PrimeFaces
, Java 8Slide39
Questions?
Marty Hall, hall@coreservlets.com
coreservlets.com
Customized Java EE and JavaScript Training