jsf 2.0 preview

45
JSF 2.0 PREVIEW Cagatay Civici

Upload: sampetruda

Post on 25-Jun-2015

1.174 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: JSF 2.0 PREVIEW

JSF 2.0 PREVIEWCagatay Civici

Page 2: JSF 2.0 PREVIEW

About MeApache MyFaces PMC MemberCo-author of “The Definitive Guide to Apache MyFaces and Facelets”Reference in “Core JSF 2nd Edition”Recognized speaker in international and local conferences (JSFOne, JSFDays...)Oracle RCF MemberKrank Framework committerJSF Chart Creator AuthorYUI4JSF Project LeadFacesTrace Project LeadFC Barcelona FanWorking for SpringSource

Page 3: JSF 2.0 PREVIEW

AgendaOverview of JSF 1.x

Overview JSF 2.0

What is new?

Future of JSF

Page 4: JSF 2.0 PREVIEW

JSF 1.x OverviewComponent Oriented

JSF 1.0, 1.1 and 1.2

Standard (jsr 127 and 252)

Two implementations

Apache MyFaces

Mojarra (RI)

Page 5: JSF 2.0 PREVIEW

JSF 1.x - The GoodComponent oriented

Extendible

Third party components (Trinidad, Tomahawk, RichFaces, IceFaces ...)

Rapid application development

Vendor and Tool support

Page 6: JSF 2.0 PREVIEW

JSF 1.x - The BadJSP based

Performance

Not very rich

Exception handling

Too much xml

A bit more...

Page 7: JSF 2.0 PREVIEW

JSF 2.0 OverviewJSR 314

Part of JEE 6

New features, improvements and fixes

Influenced by community and trends

Other web frameworks, Ajax, JSF extensions, Component libs, blogs etc...

Page 8: JSF 2.0 PREVIEW

RoadmapJSR process started in July, 2007

Early Draft Review 1 finished on July 2008

Early Draft Review 2 finished on Oct 2008

Proposed Final Draft Date, December 2008

Timed with JEE 6

Page 9: JSF 2.0 PREVIEW

So What’s New?AJAX

Easy Component Development

Resource Loading

PDL (Page Description Language)

More Scopes

Less configuration

Page 10: JSF 2.0 PREVIEW

MoreComponent interoperability

Scripting (Groovy)

Zero deployment time

System Events

Project Stage

Client side validation

Page 11: JSF 2.0 PREVIEW

More...Bookmarks

Exception handling

Improved State Management

Extension Prioritization

Page 12: JSF 2.0 PREVIEW

Resource HandlingWhat is a resource?

css, javascript, images ...A resource has;

library, version, locale, nameTwo new classes

javax.faces.application.Resourcejavax.faces.application.ResourceHandler

Load from;/resources/META-INF/resources

Page 13: JSF 2.0 PREVIEW

Resource HandlingResource Format

Examples

Ability to load from classpath

[localePrefix/] [libraryName/] [libraryVersion/] resourceName [/resourceVersion]

- tr/mycoolcomponentlib/1.0/logo.png- mycoolcomponentlib/1.0/widget.js/1.0.js- mycoolcomponentlib/styles.css

Under /resources or /META-INF/resources

Page 14: JSF 2.0 PREVIEW

Resources and Custom Components

@ResourceDependency(name=”ajaxsuggest.js”, library=”mycoolcomponentlib”)public class InputSuggest extends UIInput {...}

@ResourceDependencies({@ResourceDependency(name=”ajaxsuggest.js”, library=”mycoolcomponentlib”)@ResourceDependency(name=”ajaxsuggest.css”, library=”mycoolcomponentlib”))}public class InputSuggest extends UIInput {...}

OR

ORApplication app = FacesContext.getCurrentInstance().getApplication();Resource resource= app.getResourceHandler().createResource(“suggest.js”,”lib”);writer.write(“<script ...”); //encode using request.getRequestPath();

Page 15: JSF 2.0 PREVIEW

Resource Location4 new tags;

Example

h:headh:bodyh:outputScripth:outputStyleSheet

...<h:head></h:head><h:body>

<h:outputScript name=”suggest.js” target=”head” /></h:body>...

Page 16: JSF 2.0 PREVIEW

Resource Handling Demo

Page 17: JSF 2.0 PREVIEW

AjaxStandard JSF-Ajax integration

Javascript API for Ajax

namespace : javax.faces (Open Ajax Alliance)

script: ajax.js

Page 18: JSF 2.0 PREVIEW

Ajax Requestjavax.faces.Ajax.ajaxRequest(element,event,options)

Include ajax.js

<h:commandButton id=”btn” value=”Submit” action=”#{itemController.newItem}”onclick=”javax.faces.Ajax.ajaxRequest(this,event, {execute:this.id, render:’comp1’})”></h:commandButton>

<h:outputScript name=”ajax.js” library=”javax.faces” target=”head” />

<h:outputAjaxScript target=”head” />

OR

Page 19: JSF 2.0 PREVIEW

Ajax and Custom Components

Include ajax.js with annotation

Or with ResourceHandler

@AjaxDependency(target=”head”)public class MyAjaxComponent extends UIInput {

}

ResourceHandler.createAjaxResource();

Page 20: JSF 2.0 PREVIEW

Ajax Demo

Page 21: JSF 2.0 PREVIEW

ConfigurationAnnotations instead of xml

<managed-bean> <managed-bean-name>createBookController</managed-bean-name> <managed-bean-class>

com.bla.bla.view.MyPojo</managed-bean-class>

<managed-bean-scope>request</managed-bean-scope></managed-bean>

@ManagedBean(name=”myPojo”)@RequestScopedpublic class MyPojo {...

}

becomes

Page 22: JSF 2.0 PREVIEW

ConfigurationMore annotations

More soon...

@FacesComponent@FacesConverter@ManagedBean@ManagedBeans@ManagedProperty@FacesRenderer@FacesRenderKit@FacesValidator

Page 23: JSF 2.0 PREVIEW

Project StageProject environment settingSimilar to RAILS_ENVValues;

DevelopmentUnitTestSystemTestProduction (Default)

Page 24: JSF 2.0 PREVIEW

Project Stageweb.xml

JNDI

How to get it?

<context-param> <param-name>javax.faces.PROJECT_STAGE</param-name> <param-value>Development</param-value> </context-param>

java:comp/env/jsf/ProjectStage

Application.getProjectStage()

Page 25: JSF 2.0 PREVIEW

Project Stage Demo

Page 26: JSF 2.0 PREVIEW

System EventsSubscription based, no queueing

A bit similar to PhaseEvent idea

Ingridients

System Events

System Event Listeners

Subscribers (Application or UIComponent)

Page 27: JSF 2.0 PREVIEW

System EventsApplication level system events

public abstract void subscribeToEvent(Class<? extends SystemEvent> systemEventClass, SystemEventListener listener);

public abstract void subscribeToEvent(Class<? extends SystemEvent> systemEventClass, Class sourceClass, SystemEventListener listener); public abstract void publishEvent(Class<? extends SystemEvent> systemEventClass, SystemEventListenerHolder source);

public void publishEvent(Class<? extends SystemEvent> systemEventClass, Class<?> sourceBaseType, Object source);

Page 28: JSF 2.0 PREVIEW

System EventsUIComponent level system events

public void subscribeToEvent(Class<? extends SystemEvent> eventClass, ComponentSystemEventListener componentListener);

public void unsubscribeFromEvent(Class<? extends SystemEvent> eventClass, ComponentSystemEventListener componentListener);

AfterAddToParentEventBeforeRenderEventViewMapCreatedEventViewMapDestroyedEvent

ComponentSystemEvent

Page 29: JSF 2.0 PREVIEW

System EventsListen with annotations

@ListenerFor(systemEventClass=AfterAddToParentEvent.class)public class MyComponent extends UIOutput {}

@ListenersFor({@ListenerFor(systemEventClass=AfterAddToParentEvent.class, @ListenerFor(systemEventClass=BeforeRenderEvent.class)})public class MyComponent extends UIOutput {}

Page 30: JSF 2.0 PREVIEW

ScopesViewScope

For managed beans

Component scope

Composition

Conversation scope

Not in yet, through webbeans?

Page 31: JSF 2.0 PREVIEW

Scopes - ViewScopeA new managed bean scope

Lives until view is changed

@ManagedBean(name=”myBean”)@ViewScopedpublic class MyBeanInViewScope {...}

Page 32: JSF 2.0 PREVIEW

Scopes Demo

Page 33: JSF 2.0 PREVIEW

PDLPage Declaration Language

Based on Facelets<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"><h:head> <title>JSF2Demo</title></h:head><h:body> <h:form> <h:outputText value="Hello" /> </h:form></h:body></html>

Page 34: JSF 2.0 PREVIEW

EZCompGreatly simplifies custom component development

Convention over configuration

Declarative composite components

Components without Java coding

Component scope in composition

Page 35: JSF 2.0 PREVIEW

EZCompPage that uses a composition component

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:jwug="http://java.sun.com/jsf/composite/jwug"><h:head> <title>EZComp Demo</title></h:head><h:body> <h:form> <jwug:greeting value=”Mr. Soprano” /> </h:form></h:body></html>

Page 36: JSF 2.0 PREVIEW

EZCompUnder %webroot%/resources/jwug/greeting.xhtml

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:composite="http://java.sun.com/jsf/composite"><body><composite:interface> <composite:attribute name="value" required="true" /></composite:interface><composite:implementation>

<h:outputText value=”Hello #{compositeComponent.attrs.value}” /></composite:implementation></body></html>

Page 37: JSF 2.0 PREVIEW

EZComp - SliderScriptaculous based slider

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:jwug="http://java.sun.com/jsf/composite/jwug"><h:head> <title>EZComp Demo</title></h:head><h:body> <h:form> <jwug:slider value=”#{demo.number}” min=”0” max=”100”/> </h:form></h:body></html>

Page 38: JSF 2.0 PREVIEW

EZComp - Slider<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:composite="http://java.sun.com/jsf/composite"><body>

<composite:interface> <composite:attribute name="id" required="true" /> <composite:attribute name="value" required="true" /> <composite:attribute name="min" required="false" /> <composite:attribute name="max" required="false" /></composite:interface><composite:implementation>

<h:outputScript name="prototype.js" library="script" target="head"/><h:outputScript name="scriptaculous.js" library="script" target="head"/>

<h:inputText id="sliderField" style="width:100px" value="#{compositeComponent.attrs.value}"></h:inputText> <div id="#{compositeComponent.clientId}_track" style="width:105px;background-color:#aaa;height:5px;"> <div id="#{compositeComponent.clientId}_handle" style="width:5px;height:10px;background-color:#f00;cursor:move;"></div>

</div> <script type="text/javascript">

var slider_#{compositeComponent.attrs.id} = new Control.Slider('#{compositeComponent.clientId}_handle','#{compositeComponent.clientId}_track',{range:$R(#{compositeComponent.attrs.min},#{compositeComponent.attrs.max})});

slider_#{compositeComponent.attrs.id}.options.onSlide = function(value){ $('#{compositeComponent.clientId}:sliderField').value = (value + '').split(".")[0];};</script>

</composite:implementation></body></html>

Page 39: JSF 2.0 PREVIEW

EZComp Slider Demo

Page 40: JSF 2.0 PREVIEW

Scripting JSFGroovy instead of Java

Zero deployment time

Reload faces-config

Scripted beans, renderers, validators and etc

Page 41: JSF 2.0 PREVIEW

From JSF 2.0 Issue TrackerOptimized state managementException HandlingBookmarksSelectItemsSkinningPartial validationSecuritymore...

Page 42: JSF 2.0 PREVIEW

MyFaces 2.0Being worked on...

JSF 2.0 branch created

Not to be late this time

Page 43: JSF 2.0 PREVIEW

Future of JSFMore component libraries

JSF in EE (WebBeans, Seam, Spring Faces ...)

More RIA integration (Flex, Ajax ...)

Tool support

More adaptation

Page 44: JSF 2.0 PREVIEW

ResourcesJSF 2.0 EG blog : http://blogs.jsfcentral.com/jsf2group

Ed Burns’s blog: http://weblogs.java.net/blog/edburns/

Ryan Lubke’s blog: http://blogs.sun.com/rlubke/

Jim Driscoll’s blog: http://weblogs.java.net/blog/driscoll/

JSR Page: http://jcp.org/en/jsr/detail?id=314

Page 45: JSF 2.0 PREVIEW

The End - Cheers!

http://cagataycivici.wordpress.com

[email protected]

PS3 Network id: FacesContext