What's new and exciting with JSF 2.0

Post on 17-May-2015

3.669 views 6 download

Tags:

description

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

Transcript of What's new and exciting with JSF 2.0

Increasing JSF’s vitality with version 2.0 enhancements

By Michael FonsADF DeveloperSquareTwo Financial

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

Java professionals worldwide invigorated the JSF 2.0 redo.

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

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

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

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

Facelets creates many strong capabilities.

Facelets makes templating straightforward.

ui:composition,

ui:define,

ui:decorate, and

ui:insert

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”/>

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

Only XHTML allowed.

JSF 2.0 implements Ajax in a natural way.

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>

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>

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>

The navigation makes JSF 2.0 friendlier.

Implicit navigation makes navigation easier.

…To go to page xyz.xhtml,

you can use…

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

Post-redirect-get and bookmarkability strengthen JSF.

POST method:

<h:commandButton/> OR

<h:commandLink/>

GET method:

<h:button/> OR

<h:link/>

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”);

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

Events, Components, and Exception Handling invigorate JSF.

Expanded System Events allows precision placement of logic.

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>

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"); }

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

JSF 2.0 heals custom components development.

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”

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>

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…

Exception handling increases JSF’s IQ.

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

NOTHING IS WORKING!!!!

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

You can redefine

ExceptionHandlerFactory

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

ExceptionHandlerFactory

Can provide…

A custom ExceptionHandler

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

State Saving, View Parameters, and Resources revitalize JSF.

Toned State Saving improves JSF.

The partial state feature minimizes the state saved.Thanks,

Adam

Weiner!

Component developers enjoy the simpler syntax.StateHelper has

Eliminated

The need for…

saveState() and

restoreState()

@Overrides!

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

is needed for component developers.

View Parameters increase JSF developers’ options.

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>

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}”/>

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”/>

JSF 2.0 power-lifts resource access for custom components.

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 { …

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

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

…where [ ] indicate optionality

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

/resources/…

…or in

META-INF/resources/…

…somewhere on the classpath.

Has the JSF 2.0 team detoxified JSF 1.x?

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

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

Increasing JSF’s vitality with version 2.0 enhancements…

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

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

Contact Info:mfons@squaretwofinancial.com