A Complete Tour of JSF 2

download A Complete Tour of JSF 2

If you can't read please download the document

Transcript of A Complete Tour of JSF 2

A Complete Tour of
JavaServer Faces 2.0

Jim [email protected] [email protected]

Heading should be V3 Express?Change the dates and names

What's new?

Almost Everything

Faces Expert Group

Sun Ed Burns, Roger Kitain (Spec leads)

Oracle

Apache

IceFaces

RichFaces

RedHat / Seam

Book Authors

Many more

All of the Faces of Faces at Sun

R

Ed Burns

Jim Driscoll

Roger Kitain

Ryan Lubke

Most of the Faces of the EG

Andy Schwartz

Dan Allen

Alexandr Smirnov

Ken Paulsen

Martin Marinschek

Pete Muir

Kito Mann

Joe Ottinger

Ted Goddard

Neil Griffin

Jason Lee

David Geary

Mike Freedman

Gavin King

R

Jeremy Grelle

Keith Donald

Ed Burns

Jim Driscoll

Roger Kitain

Ryan Lubke

Some Faces of the Faces Community

Andy Schwartz

Dan Allen

Jacob Hookom

Alexandr Smirnov

Ken Paulsen

Martin Marinschek

Matthias Weendorf

Pete Muir

Alexander Jesse

Imre Owald

Yara Senger

Lincoln Baxter III

Adam Winer

Craig McClanahan

Kito Mann

Rick Hightower

Joe Ottinger

Ted Goddard

Neil Griffin

Jason Lee

Stan Silvert

David Geary

Mike Freedman

Gavin King

Hazem Saleh

aatay ivici

Dennis Byrne

Roger Keays

Amy Fowler

Max Katz

R

Jeremy Grelle

Keith Donald

Community Ideas

Innovation happens everywhere

Most ideas were proven in the community before adoption

Some approaches (i.e., Ajax) required a good deal of merging

Highlights on each feature

Features, features

Facelets

Facelets

Almost exactly the same as existing Facelets technology

JSP still supported, but...All new features will be in Facelets

Facelets now the preferred View Declaration Language

Designed for JSF from the beginning

Facelets

XHTML based document validation

Better error handling, including line numbers

Library prefixes as namespaces

EL directly in page:#{bean.propertyname}

Templating made easyui:composition, ui:define, ui:insert

ui:include, ui:repeat

Composite Components

This...

Becomes this...

Or maybe this:

Composite Components

Enable True AbstractionCreate a true, reusable, component from an arbitrary region of a page

Built by composing other components

Full support for using attached objects in the using page, and mapping them to arbitrary targets within the composite componentAction methods

Validators, etc

Composite Components

Builds on top of Resources and Facelets

Heavily leverages naming conventionsResource dir

Library name is directory name

Tag name is file name

Essentially special-case templating

Composite Component

In file ctx-root/resources/simpleout/out.xhtml:

Composite Component

.... ....

Ajax

Ajax

Inspiration: ADF Faces, RichFaces, IceFaces, DynamicFaces

Two entry points:Declarative: tag, uses AjaxBehavior

Programmatic ajax: resource library javax.faces, resource name jsf.js, JavaScript namespace jsf.ajax. jsf.ajax.request function

Ajax

Declarative ajax: useful to ajaxify non ajax pagesAdd ajax behaviors invisibly

Supports many Ajax usecases

JavaScript Ajax API usage patternjsf.ajax.request() JavaScript function

Integrate with existing Ajax widgets

Simplify lifecycle view: execute and render

Ajax Tag Example

Partial State Saving

Partial State Saving

Inspired by Trinidad state saving

Save only the state that's changed since creation of the component tree

Per-view state size up to 4X smaller than before

Default for pages written with Facelets

Of interest to Java custom component authors

All standard components implement this feature - your composite components will automatically take advantage of it.

Partial State Saving

PartialStateHolder behavioral interface, extends existing StateHolder.PartialStateHolder.markInitialState()

StateHelper, from UIComponent, does most of the work: replace ivars with keys within StateHelperNo longer need custom saveState/restoreState() implementations

Simplify Custom Components

public class MyInput extends UIComponentBase { private enum Keys { name }

public String getName() { return getStateHelper().get(name); }

public void setName(String nameParam) { getStateHelper().put(name, nameParam); }}

View Parameters

View Parameters

Inspired by Page Parameters from JBoss Seam

Provides a way to map request parameters to special components within the view

View Parameters

page1.xhtml?foo=bar

bean.foo will equal bar

View Parameters

UIViewParameter extends UIInput

All attached objects valid for UIInput are valid validation and conversion

Breaks the tyranny of POST

Lays the foundation for Bookmarkable pages

System Events

System Events

Influenced by JSFTemplatingInspired by Solaris Dtrace, Linux strace, etc.

Publish/Subscribe event bus for things that happen during the JSF Lifecycle

Adds to event listening abilities:FacesEvent/FacesListener

PhaseEvent/PhaseListener

SystemEvent/SystemEventListener

System Event Types

System Events

Listeners can be registered at three scopescomponent UIComponent.subscribeToEvent()

view UIViewRoot.subscribeToEvent()

application Application.subscribeToEvent()

Publish is always Application.publishEvent()

Declarative System Events

Resources

Resources

Avoid need for separate Filter or Servlet.

Resources are logically related to components, treat them that way.

Load from Classpath, or filesystem

Full support for Library concept, I18N, Versioning

Resources Java API

@ResourceDependency or @ResourceDependencies annotation onUIComponent, Renderer, Validator, Converter, ClientBehavior

attributes for resource name, library name

attribute for target: head, body, form

Built in support for CSS, Image, JavaScript resources

test

Resources Markup API

, Used for resource relocation targets

, Attributes for resource name, library name

Attribute for target: head, body, form

Smart includes, useful for composite components

Resource EL

#{resource['']}

#{resource[':']}

Examples of use

Behaviors

Behaviors

A Behavior is an interface and invents a new type of attached object which takes part in decode/encode.

ClientBehavior extends Behavior

Define things that happen in the view, in the browser

Currently only one standard ClientBehavior implementation: AjaxBehavior

New interface: ClientBehaviorHolder, implemented by all components in javax.faces.component.html

Special ClientBehaviorRenderer, does not extend Renderer. getScript(), decode()

View Traversal

View Traversal

1.2: UIComponent.invokeOnComponent() Single component in context

VisitContext.createVisitContext()

UIComponent.visitTree(VisitContext)Multiple components in context

Used on Ajax requests for partial traversal

Used by new StateManagementStrategy

More features

Annotations

Navigation

Exceptions

Validation

EL

Scopes

Project Stage

Annotations

@ManagedBean

@*Scoped (Session, Request, etc)

@ManagedProperty

@FacesComponent

@FacesConverter

etc.

With implicit Navigation, may eliminate need for faces-config.xml in many cases

Navigation

Bookmarkable PagesUses View Parameters to ensure request params are validated before rendering page

New components , , cause the browser to submit GET request, contrast with

add GET params

Inverse mapping of view params

Navigation

Implicit NavigationIf you dont want all that stuff, you can put the navigation logic straight in the page.

Conditional Navigation if statements

ConfigurableNavigationHandlerQuery navigation rules at run-time

Exceptions

ExceptionHandlercan be decorated

all interesting exceptions flow through the exception handler!

new exception type: UpdateModelException

ValidatorException contains multiple FacesMessages

EL

#{component}, #{cc} (composite component): get the currently processed component / composite component

#{component.clientId}

#{component.messageList}

EL

Make ActionEvent param optional for action-listeners

For EE6, EL method invocation supports parametersmakes f:setPropertyActionListener obsolete

Validation

Integration with JSR 303: Bean Validation@NotEmpty private String name;

default validator: javax.faces.Bean automatically applied to all input fields

Default-validator: hook up a validator for all instances of EditableValueHolder

preValidate/postValidate system events

New Validation Tags

Beans validation tag

Required field

Regular expression validation

New Scopes

conversation comes from Java Contexts and Dependency Injection (JSR 299) nee Weld

Flash: inspired by Ruby on Rails accessible from EL or ExternalContext

useful for storing data for use on the next request

preserves FacesContext-messages across redirects

New Scopes

View: persists as long as user interacts with the same viewmanaged-beans can be put in view-scope

Custom Scopes

Project Stage

Inspired by Rails

DevelopmentBetter error reporting, debugging

ProductionBetter performance

Using JSF 2.0 Now

Project MojarraFCS in a few weeks

https://javaserverfaces.dev.java.net/

Color coded JavaDocs
http://javaserverfaces.dev.java.net/docs/2.0/

New in 2.0

Changed in 2.0

Deprecated in 2.0 (JSP)

M

Blogs for more detail

http://andyschwartz.wordpress.com/2009/07/31/whats-new-in-jsf-2/

http://www.java.net/blogs/driscoll/

http://blogs.sun.com/rlubke/

http://www.java.net/blogs/edburns/

http://www.java.net/blogs/rogerk/

Further Reading

http://javaserverfaces.dev.java.net/docs/2.0

David Geary's writeup:http://www.ibm.com/developerworks/java/library/j-jsf2fu1/index.html

Java EE Tutorial (out soon)

Several additional books will be out this year

A Complete Tour of
JavaServer Faces 2.0

Jim [email protected] [email protected]

Heading should be V3 Express?Change the dates and names

Click to edit the title text format

Presenters NamePresenters TitlePresenters Company

Click to edit the notes format

Page

Click to edit the title text format

Click to edit the outline text formatSecond Outline LevelThird Outline LevelFourth Outline LevelFifth Outline LevelSixth Outline LevelSeventh Outline LevelEighth Outline LevelNinth Outline Level

Exact File Name

10/14/09

Page