what's new and exciting with jsf 2.0

54
Increasing JSF’s vitality with version 2.0 enhancements By Michael Fons ADF Developer SquareTwo Financial

Upload: michael-fons

Post on 17-May-2015

3.673 views

Category:

Lifestyle


6 download

DESCRIPTION

This presentation (best viewed with the notes view in ppt, individually) is an overview of new features of JSF 2.0.

TRANSCRIPT

Page 1: What's new and exciting with JSF 2.0

Increasing JSF’s vitality with version 2.0 enhancements

By Michael FonsADF DeveloperSquareTwo Financial

Page 2: What's new and exciting with JSF 2.0

Many JSF developers were not thriving with JSF 1.x.

Page 3: What's new and exciting with JSF 2.0

Java professionals worldwide invigorated the JSF 2.0 redo.

Page 4: What's new and exciting with JSF 2.0

JSF 1.x turned out to be weak, and needed to become more fit.

Page 5: What's new and exciting with JSF 2.0

JSF 2.0 has infused JSF with life and given JSF back its edge.

Page 6: What's new and exciting with JSF 2.0

The Java EE community builds its health by adopting JSF 2.0!

Page 7: What's new and exciting with JSF 2.0

Features like Facelets, Navigational changes, and Ajax strengthen JSF.

Page 8: What's new and exciting with JSF 2.0

Facelets creates many strong capabilities.

Page 9: What's new and exciting with JSF 2.0

Facelets makes templating straightforward.

ui:composition,

ui:define,

ui:decorate, and

ui:insert

Page 10: What's new and exciting with JSF 2.0

Developers can easily create composite components now.Caller page:<xyz:myComp …> <f:validateLength for=“myClientId” …/></xyz:myComp>Composite component Interface section:<cc:editableValueHolder name=“myClientId”…/>Composite component Implementation:<h:inputText … id=“myClientId”/>

Page 11: What's new and exciting with JSF 2.0

Using XHTML now eliminates scriptlets.Not allowed <% …java code … %>

Only XHTML allowed.

Page 12: What's new and exciting with JSF 2.0

JSF 2.0 implements Ajax in a natural way.

Page 13: What's new and exciting with JSF 2.0

Tiny syntactical changes tap into lots of Ajax capability.Non-AJAX

<h:form>

<h:inputText …/>

<h:commandButton …/>

</h:form>

Using AJAX<f:ajax …><h:inputText …/></f:ajax>OR<h:form><h:inputText …><f:ajax render=“@form”/></h:inputText></h:form>

Page 14: What's new and exciting with JSF 2.0

Developers do not need any JavaScript in many cases. <h:form id="form"><!-- ******M E T H O D 1********** --> <h:outputText id="output" value="You entered #{requestScope['input']}."/> <h:inputText id="input“ value="#{requestScope.input}”> <f:ajax render="form:output“ event="keyup"/> </h:inputText></h:form>

Page 15: What's new and exciting with JSF 2.0

A developer can still implement any custom Ajax solution.<h:form id="form"><!-- *******M E T H O D 2******** --> <h:outputText id="output2" value="You entered #{requestScope['input2']}."/> <h:inputText id="input2" value="#{requestScope.input2}" onkeyup="var lArgs = {}; lArgs['render'] = 'form:output2'; lArgs['javax.faces.behavior.event'] = 'keyup'; jsf.ajax.request(this,event,lArgs);”> <!-- If I did not want to change from the default event for the inputText, the call would be jsf.ajax.request(this, event, {render:’form:output2’}); but I want to change the event, and they have named that property with periods in it. in jsf.js line 1659 I am getting an error because there is a syntax problem when I set javax.faces.behaviour.event property to keyup because the periods in the property name throw the js interpreter off-->

</h:inputText></h:form>

Page 16: What's new and exciting with JSF 2.0

The navigation makes JSF 2.0 friendlier.

Page 17: What's new and exciting with JSF 2.0

Implicit navigation makes navigation easier.

…To go to page xyz.xhtml,

you can use…

<h:comandButton action=“xyz” … />

Page 18: What's new and exciting with JSF 2.0

Post-redirect-get and bookmarkability strengthen JSF.

POST method:

<h:commandButton/> OR

<h:commandLink/>

GET method:

<h:button/> OR

<h:link/>

Page 19: What's new and exciting with JSF 2.0

Flash supplements JSF navigation.Using EL:#{flash.someVariable}…to keep what is already stored there for another request…#{flash.keep.someVariable}

Using Java:Flash lFlash = FacesContext.getCurrentInstance().getExternalContext().getFlash();lFlash.get(“someVariable”);

Page 20: What's new and exciting with JSF 2.0

JSF 1.1/1.2 have lost favor due to their unhealthiness.

Page 21: What's new and exciting with JSF 2.0

Events, Components, and Exception Handling invigorate JSF.

Page 22: What's new and exciting with JSF 2.0

Expanded System Events allows precision placement of logic.

Page 23: What's new and exciting with JSF 2.0

Application create/destroy and exceptions now all create events.<application> <system-event-listener> <system-event-listener-class>mfons.experiments.jsf20.TestPostConstructApplicationEventListener</system-event-listener-class> <system-event-class>javax.faces.event.PostConstructApplicationEvent</system-event-class> </system-event-listener> <system-event-listener> <system-event-listener-class>mfons.experiments.jsf20.TestPostConstructApplicationEventListener</system-event-listener-class> <system-event-class>javax.faces.event.PreDestroyApplicationEvent</system-event-class> </system-event-listener></application>

Page 24: What's new and exciting with JSF 2.0

Component events now include AJAX, validation, and state.…this statement…<f:ajax … listener="#{myBean.checkAjaxBehavior}"/>…creates this event for each Ajax event for the components to which this f:ajax tag applies… public void checkAjaxBehavior(AjaxBehaviorEvent pEvent){ System.out.println("This inputText has Ajax behavior and it is right now undergoing a decode method call in the request values phase of the JSF request lifecycle"); }

Page 25: What's new and exciting with JSF 2.0

Removal from view and scope changes increase events.Good reference to know when PostAddToViewEvent and PreRemoveFromViewEvent are fired:

https://issues.apache.org/jira/browse/MYFACES-2638

Page 26: What's new and exciting with JSF 2.0

JSF 2.0 heals custom components development.

Page 27: What's new and exciting with JSF 2.0

Beginners can quickly combine components to make their own.A using page references…xmlns:<library reference>=http://java.sun.com/jsf/composite

</optional library name>

…and will reference…<lr:xyz …/>

…if the library reference is “lr” and the name of the definition file is “resources</optional library name>/xyz.xhtml”

Page 28: What's new and exciting with JSF 2.0

Intermediates can add much complexity simply in most cases.<cc:interface>

<cc:attribute name=“someattr”/>

<cc:editableValueHolder … />

<cc:actionSource … />

</cc:interface>

<cc:implementation>

<h:outputText value=“#{cc.attrs.someattr}”/>

</cc:implementation>

Page 29: What's new and exciting with JSF 2.0

JSF 2.0 still has its old custom component options for experts.Non-composite component authors define…

…UIComponent Java class

…Facelets tag library

…Renderers

…tag handlers

Easier state management, now…

Page 30: What's new and exciting with JSF 2.0

Exception handling increases JSF’s IQ.

Page 31: What's new and exciting with JSF 2.0

Unhandled errors are disruptive to an application.Nobody wants to hear…

NOTHING IS WORKING!!!!

Page 32: What's new and exciting with JSF 2.0

Having a consistent error handling interface is calming....in faces-config.xml…

You can redefine

ExceptionHandlerFactory

Page 33: What's new and exciting with JSF 2.0

Now global error-handling schemes can be found.The custom

ExceptionHandlerFactory

Can provide…

A custom ExceptionHandler

Page 34: What's new and exciting with JSF 2.0

JSF 1.1/1.2 have lost favor due to their unhealthiness.

Page 35: What's new and exciting with JSF 2.0

State Saving, View Parameters, and Resources revitalize JSF.

Page 36: What's new and exciting with JSF 2.0

Toned State Saving improves JSF.

Page 37: What's new and exciting with JSF 2.0

The partial state feature minimizes the state saved.Thanks,

Adam

Weiner!

Page 38: What's new and exciting with JSF 2.0

Component developers enjoy the simpler syntax.StateHelper has

Eliminated

The need for…

saveState() and

restoreState()

@Overrides!

Page 39: What's new and exciting with JSF 2.0

Developers now say when a component has its initial state.PartialStateHolder.markInitialState()

is needed for component developers.

Page 40: What's new and exciting with JSF 2.0

View Parameters increase JSF developers’ options.

Page 41: What's new and exciting with JSF 2.0

Developers can declaratively define GET parameters.In caller page link/button outcome…

someoutcome?faces-redirect=true&amp;includeViewParams=true

In target page…

<f:metadata>

<f:viewParam …/>

</f:metadata>

Page 42: What's new and exciting with JSF 2.0

The parameters implement EditableValueHolder.…can write to model…

<f:viewParam name=“something”

value=“#{some.valueExpression}” />

…can invoke application logic…

<f:event type=“preRenderView”

listener=“#{some.preRenderViewEventListenerMethod}”/>

Page 43: What's new and exciting with JSF 2.0

You can create bookmarkable links with these parameters.…supports bookmarkability…

<h:link …/>/<h:button …/>

…example:

<h:link outcome=“currentPageName?faces-redirect=true&amp;includeViewParams=true” value=“bookmarkable link to this page”/>

Page 44: What's new and exciting with JSF 2.0

JSF 2.0 power-lifts resource access for custom components.

Page 45: What's new and exciting with JSF 2.0

JSF 2.0 easily serves resources to custom components.@FacesRenderer(rendererType = “…", componentFamily = “…")@ResourceDependencies({        @ResourceDependency(name = “mycss.css", library = “mystyle", target = "head"), …})public class MyRenderer extends Renderer { …

Page 46: What's new and exciting with JSF 2.0

Developers can install new resource versions instantly.In resources directory…

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

…where [ ] indicate optionality

Page 47: What's new and exciting with JSF 2.0

Resource files will now reside in predictable locations.…either in docroot:

/resources/…

…or in

META-INF/resources/…

…somewhere on the classpath.

Page 48: What's new and exciting with JSF 2.0

Has the JSF 2.0 team detoxified JSF 1.x?

Page 49: What's new and exciting with JSF 2.0

JSF 1.1/1.2 have lost favor due to their unhealthiness.

Page 50: What's new and exciting with JSF 2.0

The Java EE community builds its health by adopting JSF 2.0!

Page 51: What's new and exciting with JSF 2.0

Increasing JSF’s vitality with version 2.0 enhancements…

Page 52: What's new and exciting with JSF 2.0

JSF 2.0 is out, and it’s better than ever!

Page 53: What's new and exciting with JSF 2.0

Resources

http://blogs.sun.com/rlubke/entry/jsf_2_0_new_feature for help on resources.JavaServer Faces 2.0: the complete reference, by Ed Burns, Chris Schalk, McGraw-Hill, 2010.http://andyschwartz.wordpress.com/2009/07/31/whats-new-in-jsf-2/ http://javaserverfaces.java.net/nonav/docs/2.0/javadocs/javax/faces/component/PartialStateHolder.htmlhttp://blogs.sun.com/jasondlee/entry/jsf_2_gets_declarative_eventhttp://myfaces.apache.org/core20/myfaces-api/apidocs/javax/faces/event/ComponentSystemEvent.htmlhttp://weblogs.java.net/blog/edburns/archive/2009/09/02/jsf2-composite-component-metadatahttp://weblogs.java.net/blog/jhook/archive/2006/01/experiment_goin_1.htmlhttp://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-157http://www.slideshare.net/jimdriscoll/jsf-2-and-ajaxhttp://code.google.com/p/teknoatolye/source/browse/trunk/sinek/src/main/java/org/mca/sinek/jsf/SinekRenderer.javahttps://issues.apache.org/jira/browse/MYFACES-2638

Page 54: What's new and exciting with JSF 2.0

Contact Info:[email protected]