SlideShare una empresa de Scribd logo
1 de 42
Descargar para leer sin conexión
What‘s new in JavaServer Faces (JSF2)
PAVONE AG Kai Jemella
- Consultant Business & IT-Services -
What is new in JSF 2.0
Configuration
Facelets View Declaration Language / Templates
Facelets Composite Components
Validation
State Saving / System Events / Behaivor
GET Support / Navigation / Scopes
Resource Loading / Error Handling
Ajax
Configuration – Annotations
JSF 1.2 : faces-config.xml
<managed-bean>
<managed-bean-name>foo</managed-bean-name>
<managed-bean-class>com.foo.Foo</managed-bean-class>
<managed-bean-scope>session</managed-bean>
</managed-bean>
JSF 2.0 : Managed Bean Annotation
@ManagedBean
@SessionScoped
public class Foo {
}
Configuration – Annotations
JSF 2.0 : Component Annotations
@FacesComponent
@FacesRenderer
@FacesConverter
@FacesValidator
@FacesBehavior
Configuration faces-config.xml Order
JSF 1.2:
Loaded based on an order derived from the containing jar file’s
name.
JSF 2.0:
Reference other faces-config-xml by <name> element e.g. for view-
handler or phase-listener.
<faces-config>
<name>bar</name>
</faces-config>
<faces-config>
<name>foo</name>
<ordering>
<after>
<name>bar</name>
</after>
</ordering>
</faces-config>
<faces-config>
<name>foobar</name>
<ordering>
<before>
<others/>
</before>
</ordering>
</faces-config>
Configuration - Notice
Notice that even if we are using JSF 2.0, we still need the
Facesconfig.xml file. Annotations and the implicit navigation allow us
to write an application without needing a faces-config.xml
fille. but there are still cases where the configuration file is needed.
Localization information, advanced features such as ELResolvers,
PhaseListeners, or artifacts that rely on the decorator pattern
still require a faces-config.xml file.
(JSF 2.0 Cookbook, Anghel Leonard, PACKT PUBLISHING)
What is new in JSF 2.0
Configuration
Facelets View Declaration Language / Templates
Facelets Composite Components
Validation
State Saving / System Events / Behaivor
GET Support / Navigation / Scopes
Resource Loading / Error Handling
Ajax
Improving JSF by Dumping JSP
Several JSF Alternatives to JSP
Apache Shale’s Clay
JSF Templating
Facelets
JSF 2.0: addresses this by
ViewDeclarationLanguage allows frameworks to define their own
view declaration language
Standard non JSP view declaration language Facelets 2.0 (should
be very familiar to Facelets 1.x)
Facelets View Declaration Language / Templates
Facelets View Declaration Language / Templates
JSP
<@ taglib uri="http://java.sun.com/jsf/html" prefix="h">
<@ taglib uri="http://java.sun.com/jsf/core" prefix="f">
<html>
<head><title>Show Customer</title></head>
<body>
<f:view>
<h1><h:outputText value="Show Customer"/></h1>
<!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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<head><title>Show Customer</title></head>
<body>
<h1><h:outputText value="Show Customer"/></h1>
Facelets
Facelets View Declaration Language / Templates
Template html
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<head>…</head>
<body>
<div id="header">
<ui:insert name="header"><h1>MyGourmet</h1></ui:insert>
<div id="content"><ui:insert name="content"/></div>
</div>
</body></html>
<body>
<ui:composition template="template.xhtml">
<ui:define name="content">
<h2>Customer</h2>
<h:panelGrid id="grid" columns="2">
<h:outputText value="Given name"/>
<h:outputText value="#{customer.givenName}"/>
<h:outputText value="Lastname" />
<h:outputText value="#{customer.lastName}"/>
</h:panelGrid>
</ui:define>
</ui:composition>
</body>
Facelet
Facelets View Declaration Language / Templates
Multiple templates
<ui:composition template="template.xhtml">
...
<ui:define name="left_sidebar">
<ui:decorate template="sideBox.xhtml">
<ui:param name="title" value="Messages"/>
<h:outputText value="#{bean.msg}"/>
</ui:decorate>
</ui:define>
...
</ui:composition>
What is new in JSF 2.0
Configuration
Facelets View Declaration Language / Templates
Facelets Composite Components
Validation
State Saving / System Events / Behaivor
GET Support / Navigation / Scopes
Resource Loading / Error Handling
Ajax
Facelets Composite Components
Simplifies custom component development
JSF 2.0: Create Components with a single file without Java
First create tag library xml file and declare it in web.xml
<facelet-taglib>
<namespace>http://www.my.facelets.component.com/jsf</namespace>
<tag>
<tag-name>sayhello</tag-name>
<source>sayhello.xhtml</source>
</tag>
</facelet-taglib>
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/facelets/tags/mycomponents.xml</param-value>
</context-param>
Facelets Composite Components
Composite Component
<!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:composite="http://java.sun.com/jsf/composite">
<head>…</head>
<body>
<composite:interface>
<composite:attribute name="who"/>
</composite:interface>
<composite:implementation>
<h:outputText value="Hello, #{cc.attrs.who}!"/>
</composite:implementation>
</body>
</html>
Use Component
<html … xmlns:mycomp="http://java.sun.com/jsf/composite/greet">
<mycomp:sayhello who="World"/>
</html>
Facelets Composite Components
Think LEGOs
Passing sub-elements to compsition components
Passing actions to composition components
Insert facets, adding children, attaching listeners, validators, …
Mixing JSF and Dojo widget for custom components
What is new in JSF 2.0
Configuration
Facelets View Declaration Language / Templates
Facelets Composite Components
Validation
State Saving / System Events / Behaivor
GET Support / Navigation / Scopes
Resource Loading / Error Handling
Ajax
Validation
JSF 2.0: Bean Validation built-in integration with JSR-303 constraints.
<!-- provides bean validation -->
<f:validateBean>
<!-- provides required field validation -->
<f:validateRequired>
<!-- provides regular expression-based validation -->
<f:validateRegexp>
JSF 2.0: Additional Validation tags
Validation – Bean Validation
JSF 2.0: Bean Validation Annotation
public class FooBar {
@NotNull @Min(value = 1000) @Max(value = 99999)
private Integer foo;
@NotNull
private String bar;
}
JSF 2.0: Bean Validation JSR-303 custom validator and constraints
@Constraint(validatedBy = FooBarValidator.class)
…
public @interface FooBar { … }
public class FooBarValidator
implements ConstraintValidator<FooBar, Date> { … }
Validation – Bean Validation
JSF 2.0: Bean Validation Groups
public interface usersIdsGroup {}
public interface usersCredentialsGroup {}
public userBean{
@NotEmpty(message = "The name cannot be empty!",
groups = beans.usersIdsGroup.class)
private String name;
@Size(min = 5, max = 20, message = "You …",
groups = beans. usersCredentialsGroup.class)
private String password;
JSF 2.0: validationGroups
<f:validateBean validationGroups="beans.usersIdsGroup, otherGroup">
<h:outputText value="Name:"/>
<h:inputText value="#{userBean.name}"/>
</f:validateBean>
Validation Annotations
@AssertFalse // check element is false
@AssertTrue // check element is true
@DecimalMax // check number lower or equal
@DecimalMin // check number higher or equal
@Digits // check number digits and fraction
@Future // check date is in the future
@Max // check less than or equal
@Min // check higher than or equal
@NotNull // check not null
@Null // check null
@Valid // validation by associated object
@Past // check date is in the past
@Pattern // check by pattern
@Size // check size ist between min and max
//not in bean validation specification -> hibernate validator
@Length, @NotEmpty, @ Email, @Range
Validation Notice
<context-param>
<param-name>
javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL
</param-name>
<param-value>true</param-value>
</context-param>
JSF 2.0: @NotNull context parameter
What is new in JSF 2.0
Configuration
Facelets View Declaration Language / Templates
Facelets Composite Components
Validation
State Saving / System Events / Behaivor
GET Support / Navigation / Scopes
Resource Loading / Error Handling
Ajax
State Saving
JSF 2.0: new State Saving
Problem size of the saved state can be large
Component developers can now use PartialStateHolder and
StateHelper
Save only modified state since view initially created
System Events
JSF 2.0 new SystemEvents
Global SystemEvents Application initialization / destruction
Component System Events
Component added to view
Component rendered
Component validated
<h:inputText>
<f:event type="preValidate« 
listener="#{bean.doSomePreValidation}"/>
</h:inputText>
Behaivor
JSF 2.0 new class ClientBehavior, ClientBehaivorHolder
e.g. AjaxBehavior f:ajax
Enhancing client-side of components
Prevent hand-conding scripts and manually wiring these scripts
<h:commandButton>
<!--First ask for confirmation -->
<foo:confirm event="click"/>
<!-- If successful, send an Ajax request -->
<f:ajax event="click"/>
</h:commandButton>
Behaivor
JSF 2.0 confirm behaivor
@FacesBehavior("foo.behavior.Confirm")
public class ConfirmBehavior extends ClientBehaviorBase
{
@Override
public String getScript(
ClientBehaviorContext behaviorContext) {
return "return confirm('Are you sure?')";
}
}
Behaivor
JSF 2.0 Append Behavior in taglib
<?xml version='1.0' encoding='UTF-8'?>
<facelet-taglib xmlns="http://java.sun.com/xml/ns/javaee"
version="2.0">
<namespace>http://example.org/foo</namespace>
<tag>
<tag-name>confirm</tag-name>
<behavior>
<behavior-id>foo.behavior.Confirm</behavior-id>
</behavior>
</tag>
</facelet-taglib>
What is new in JSF 2.0
Configuration
Facelets View Declaration Language / Templates
Facelets Composite Components
Validation
State Saving / System Events / Behaivor
GET Support / Navigation / Scopes
Resource Loading / Error Handling
Ajax
Navigation
Conditional navigation for pre-condition
<navigation-rule>
<from-view-id>/foo.xhtml</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/bar.xhtml</to-view-id>^
<if>#{foo.someCondition}</if>
</navigation-case>
</navigation-rule>
Reduce navigation related grunch code
Implicit navigation e.g. action outcome corresponds to a view id
ConfigurableNavigationHandler (available navigation rules/cases)
Dynamically control the application flow
GET Support
<f:metadata>
<f:viewParam name="foo" value="#{bean.foo}" required="true"
requiredMessage="This parameter is a must!"/>
<!-- PreRenderViewEvent -->
<f:event type="preRenderView" listener="#{bean.doSomething}"/>
</f:metadata>
JSF 1.2: value processing of values via HTTP Post
JSF 2.0: view parameters for HTTP e.g. page1.xhtml?foo=bar
<h:link outcome="success" includeViewParams="true">
<f:param name="foo" value="bar"/>
</h:link>
JSF 2.0: view parameter inverse mapping and manual parameter
Scopes
JSF 2.0: view scope
„longer than request, shorter than session“
Until the user finishes interaction with the current view
UIViewRoot.getViewMap() or EL #{viewScope}
JSF 2.0: flash scope
Concept from Rails
Short-lived conversation
State survives a redirect e.g. page2?faces-redirect=true
ExternalContext.getFlash() or EL #{flash}
JSF 2.0: Custom Scopes to place managed beans into custom scope
What is new in JSF 2.0
Configuration
Facelets View Declaration Language / Templates
Facelets Composite Components
Validation
State Saving / System Events / Behaivor
GET Support / Navigation / Scopes
Resource Loading / Error Handling
Ajax
Resource Loading / Error Handling
JSF 2.0: @ResourceDependency
@ResourceDependency(name="my.css",library="libus")
public class MyComponent extends UIComponentBase {
…
}
JSF 2.0: ResourceHandler e.g. images, JavaScript, stylesheets, …
/resources/css/foobar.css
/resources/images/foobar.jpg
/resources/javascript/foobar.js
<h:graphicImage library="images" name=“foobar.jpg"/>
<h:outputStylesheet library="css" name=“foobar.css"/>
<h:outputScript library="javascript" name=“foobar.js” target="head"/>
<!-- via EL -->
<h:graphicImage value="#{resource['images:foobar.jpg']}"/>
Resource Loading / Error Handling
JSF 2.0: ExceptionHandler API (central excpetion handling)
<error-page>
<exception-type>java.lang.NumberFormatException</exception-type>
<location>/faces/error.xhtml</location>
</error-page>
What is new in JSF 2.0
Configuration
Facelets View Declaration Language / Templates
Facelets Composite Components
Validation
State Saving / System Events / Behaivor
GET Support / Navigation / Scopes
Resource Loading / Error Handling
Ajax
Ajax
JSF 2.0 (2009) four years since Ajax was coined.
JSF Ajax problem has been solved many times!
Many JSF/Ajax frameworks available.
DynamicFaces, RichFaces, ajax4jsf,
PrimeFaces, MyFaces Tomahawk …
Problem cross-framework compatibility
Isn‘t it time to Ajax without 3rd party frameworks?
Ajax
Partial View Processing and Pratial View Rendering
(IBM: http://www.ibm.com/developerworks/library/j-jsf2/)
Ajax
JSF 2.0: Ajax Parameter
javax.faces.partial.ajax
javax.faces.source
javax.faces.partial.execute
javax.faces.partial.render
Ajax
JSF 2.0: JavaScript API
<h:form id="formID" prependId="false">
<h:outputScript name="jsf.js" library="javax.faces"
target="head" />
<h:outputText id="randomID" value="#{random.random}" />
<h:commandButton id="buttonID" value="Random"
onclick="jsf.ajax.request(this, event, {execute:
this.id, render: 'randomID'}); return false;" />
</h:form>
Ajax
JSF 2.0: f:ajax tag
<h:form id="formID" prependId="false">
<h:outputText id="randomID" value="#{random.random}" />
<h:commandButton id="buttonID" value="Random">
<f:ajax execute="formID:buttonID formID:randomID"
render="formID:randomID" />
</h:commandButton>
</h:form>
Ajax Keywords
Keyword Execute Render
@all Every component on the page is submitted and
processed. This is useful when you want to do a full-
page submit.
Every component on the page is
rendered. This is useful when you
just want to rere nder the whole
page asynchronously. E.g.
update client side state outside of
JSF.
@none Execute the lifedycle, including ist phase listeners, but
no components will be traversed.
Perform the Render Response
phase, including firing any
preRenderView events, but don‘t
actually render anything.
@this Submit and process only the component to which the
<f:ajax> is applied.
Render only the component to
which the <f:ajax> is applied
@form Submit and process the entire <h:form> in which the
component thas has the <f:ajax> is nested.
Render the entire <h:form> in
which the component thas has
the <f:ajax> is nested.
(JavaServer faces 2.0: the complete reference By Ed Burns, Neil Griffin, Chris Schalk)
Resources
JSF Specification
http://jcp.org/aboutJava/communityprocess/final/jsr314/index.html
Andy Schwartz
http://andyschwartz.wordpress.com/2009/07/31/whats-new-in-jsf-2/
Irian http://jsfatwork.irian.at/book_de/
IBM Developerworks
http://www.ibm.com/developerworks/java/library/j-jsf2fu2/index.html
JSF 2.0 Cookbook, Anghel Leonard, PACKT PUBLISHING
JavaServer faces 2.0: the complete reference By Ed Burns, Neil
Griffin, Chris Schalk

Más contenido relacionado

La actualidad más candente

Workflow functional concept on openerp7
Workflow functional concept on openerp7Workflow functional concept on openerp7
Workflow functional concept on openerp7Aziza Mohamed
 
Java Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet AdvancedJava Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet AdvancedIMC Institute
 
Django class based views for beginners
Django class based views for beginnersDjango class based views for beginners
Django class based views for beginnersSpin Lai
 
Spring Web Views
Spring Web ViewsSpring Web Views
Spring Web ViewsEmprovise
 
Introduction to JSF
Introduction toJSFIntroduction toJSF
Introduction to JSFSoftServe
 
Web internship Yii Framework
Web internship  Yii FrameworkWeb internship  Yii Framework
Web internship Yii FrameworkNoveo
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsCarol McDonald
 
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for PerformanceMeet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for PerformanceIvan Chepurnyi
 
Java Web Development with Stripes
Java Web Development with StripesJava Web Development with Stripes
Java Web Development with StripesSamuel Santos
 
Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1Michał Orman
 
Using of TDD practices for Magento
Using of TDD practices for MagentoUsing of TDD practices for Magento
Using of TDD practices for MagentoIvan Chepurnyi
 
JavaScript
JavaScriptJavaScript
JavaScriptSunil OS
 
Idoc script beginner guide
Idoc script beginner guide Idoc script beginner guide
Idoc script beginner guide Vinay Kumar
 

La actualidad más candente (20)

Workflow functional concept on openerp7
Workflow functional concept on openerp7Workflow functional concept on openerp7
Workflow functional concept on openerp7
 
Jsf intro
Jsf introJsf intro
Jsf intro
 
Java Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet AdvancedJava Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet Advanced
 
Jsf
JsfJsf
Jsf
 
Django class based views for beginners
Django class based views for beginnersDjango class based views for beginners
Django class based views for beginners
 
The most basic inline tag
The most basic inline tagThe most basic inline tag
The most basic inline tag
 
Spring Web Views
Spring Web ViewsSpring Web Views
Spring Web Views
 
Introduction to JSF
Introduction toJSFIntroduction toJSF
Introduction to JSF
 
Unit testing zend framework apps
Unit testing zend framework appsUnit testing zend framework apps
Unit testing zend framework apps
 
Web internship Yii Framework
Web internship  Yii FrameworkWeb internship  Yii Framework
Web internship Yii Framework
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.js
 
Stripes Framework
Stripes FrameworkStripes Framework
Stripes Framework
 
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for PerformanceMeet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
 
Java Web Development with Stripes
Java Web Development with StripesJava Web Development with Stripes
Java Web Development with Stripes
 
MVC.net training in pune
MVC.net training in pune MVC.net training in pune
MVC.net training in pune
 
Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1
 
Using of TDD practices for Magento
Using of TDD practices for MagentoUsing of TDD practices for Magento
Using of TDD practices for Magento
 
Zend framework 04 - forms
Zend framework 04 - formsZend framework 04 - forms
Zend framework 04 - forms
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Idoc script beginner guide
Idoc script beginner guide Idoc script beginner guide
Idoc script beginner guide
 

Destacado

Photo talk
Photo talkPhoto talk
Photo talkJAMAATON
 
Sonas Housing Annual Review 2011
Sonas Housing Annual Review 2011Sonas Housing Annual Review 2011
Sonas Housing Annual Review 2011Sonas_Housing
 
Kernel Masters inauguration slideshare
Kernel Masters inauguration slideshareKernel Masters inauguration slideshare
Kernel Masters inauguration slideshareKernel Masters
 
KM Placement Assistance Program
KM Placement Assistance ProgramKM Placement Assistance Program
KM Placement Assistance ProgramKernel Masters
 
Learn BEM: CSS Naming Convention
Learn BEM: CSS Naming ConventionLearn BEM: CSS Naming Convention
Learn BEM: CSS Naming ConventionIn a Rocket
 
SEO: Getting Personal
SEO: Getting PersonalSEO: Getting Personal
SEO: Getting PersonalKirsty Hulse
 
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika AldabaLightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldabaux singapore
 

Destacado (8)

Photo talk
Photo talkPhoto talk
Photo talk
 
Sonas Housing Annual Review 2011
Sonas Housing Annual Review 2011Sonas Housing Annual Review 2011
Sonas Housing Annual Review 2011
 
Kernel Masters inauguration slideshare
Kernel Masters inauguration slideshareKernel Masters inauguration slideshare
Kernel Masters inauguration slideshare
 
KM Placement Assistance Program
KM Placement Assistance ProgramKM Placement Assistance Program
KM Placement Assistance Program
 
Learn BEM: CSS Naming Convention
Learn BEM: CSS Naming ConventionLearn BEM: CSS Naming Convention
Learn BEM: CSS Naming Convention
 
SEO: Getting Personal
SEO: Getting PersonalSEO: Getting Personal
SEO: Getting Personal
 
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika AldabaLightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
 
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job? Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
 

Similar a Neuerungen in JavaServer Faces 2.0

In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces Skills Matter
 
JavaServer Faces 2.0 - JavaOne India 2011
JavaServer Faces 2.0 - JavaOne India 2011JavaServer Faces 2.0 - JavaOne India 2011
JavaServer Faces 2.0 - JavaOne India 2011Arun Gupta
 
AnkaraJUG Kasım 2012 - PrimeFaces
AnkaraJUG Kasım 2012 - PrimeFacesAnkaraJUG Kasım 2012 - PrimeFaces
AnkaraJUG Kasım 2012 - PrimeFacesAnkara JUG
 
Javatwo2012 java frameworkcomparison
Javatwo2012 java frameworkcomparisonJavatwo2012 java frameworkcomparison
Javatwo2012 java frameworkcomparisonJini Lee
 
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0Arun Gupta
 
Integrating Wicket with Java EE 6
Integrating Wicket with Java EE 6Integrating Wicket with Java EE 6
Integrating Wicket with Java EE 6Michael Plöd
 
PrimeTime JSF with PrimeFaces - Dec 2014
PrimeTime JSF with PrimeFaces - Dec 2014PrimeTime JSF with PrimeFaces - Dec 2014
PrimeTime JSF with PrimeFaces - Dec 2014cagataycivici
 
What You Need To Build Cool Enterprise Applications With JSF
What You Need To Build Cool Enterprise Applications With JSFWhat You Need To Build Cool Enterprise Applications With JSF
What You Need To Build Cool Enterprise Applications With JSFMax Katz
 
WebClient Customization.pdf
WebClient Customization.pdfWebClient Customization.pdf
WebClient Customization.pdfsatyasekhar123
 
HTML5 New and Improved
HTML5   New and ImprovedHTML5   New and Improved
HTML5 New and ImprovedTimothy Fisher
 
How to Create A Magento Adminhtml Controller in Magento Extension
How to Create A Magento Adminhtml Controller in Magento ExtensionHow to Create A Magento Adminhtml Controller in Magento Extension
How to Create A Magento Adminhtml Controller in Magento ExtensionHendy Irawan
 
Primefaces Confess 2012
Primefaces Confess 2012Primefaces Confess 2012
Primefaces Confess 2012cagataycivici
 
JSF 2.0 (JavaEE Webinar)
JSF 2.0 (JavaEE Webinar)JSF 2.0 (JavaEE Webinar)
JSF 2.0 (JavaEE Webinar)Roger Kitain
 
카카오커머스를 지탱하는 Angular
카카오커머스를 지탱하는 Angular카카오커머스를 지탱하는 Angular
카카오커머스를 지탱하는 Angularif kakao
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Michelangelo van Dam
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenchesLukas Smith
 
Membangun Moderen UI dengan Vue.js
Membangun Moderen UI dengan Vue.jsMembangun Moderen UI dengan Vue.js
Membangun Moderen UI dengan Vue.jsFroyo Framework
 
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010Arun Gupta
 

Similar a Neuerungen in JavaServer Faces 2.0 (20)

In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
 
JavaServer Faces 2.0 - JavaOne India 2011
JavaServer Faces 2.0 - JavaOne India 2011JavaServer Faces 2.0 - JavaOne India 2011
JavaServer Faces 2.0 - JavaOne India 2011
 
AnkaraJUG Kasım 2012 - PrimeFaces
AnkaraJUG Kasım 2012 - PrimeFacesAnkaraJUG Kasım 2012 - PrimeFaces
AnkaraJUG Kasım 2012 - PrimeFaces
 
Javatwo2012 java frameworkcomparison
Javatwo2012 java frameworkcomparisonJavatwo2012 java frameworkcomparison
Javatwo2012 java frameworkcomparison
 
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
 
Struts Overview
Struts OverviewStruts Overview
Struts Overview
 
Integrating Wicket with Java EE 6
Integrating Wicket with Java EE 6Integrating Wicket with Java EE 6
Integrating Wicket with Java EE 6
 
PrimeTime JSF with PrimeFaces - Dec 2014
PrimeTime JSF with PrimeFaces - Dec 2014PrimeTime JSF with PrimeFaces - Dec 2014
PrimeTime JSF with PrimeFaces - Dec 2014
 
What You Need To Build Cool Enterprise Applications With JSF
What You Need To Build Cool Enterprise Applications With JSFWhat You Need To Build Cool Enterprise Applications With JSF
What You Need To Build Cool Enterprise Applications With JSF
 
WebClient Customization.pdf
WebClient Customization.pdfWebClient Customization.pdf
WebClient Customization.pdf
 
HTML5 New and Improved
HTML5   New and ImprovedHTML5   New and Improved
HTML5 New and Improved
 
How to Create A Magento Adminhtml Controller in Magento Extension
How to Create A Magento Adminhtml Controller in Magento ExtensionHow to Create A Magento Adminhtml Controller in Magento Extension
How to Create A Magento Adminhtml Controller in Magento Extension
 
Primefaces Confess 2012
Primefaces Confess 2012Primefaces Confess 2012
Primefaces Confess 2012
 
JSF 2.0 (JavaEE Webinar)
JSF 2.0 (JavaEE Webinar)JSF 2.0 (JavaEE Webinar)
JSF 2.0 (JavaEE Webinar)
 
카카오커머스를 지탱하는 Angular
카카오커머스를 지탱하는 Angular카카오커머스를 지탱하는 Angular
카카오커머스를 지탱하는 Angular
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8
 
JSF 2.0 Preview
JSF 2.0 PreviewJSF 2.0 Preview
JSF 2.0 Preview
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
 
Membangun Moderen UI dengan Vue.js
Membangun Moderen UI dengan Vue.jsMembangun Moderen UI dengan Vue.js
Membangun Moderen UI dengan Vue.js
 
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
 

Último

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 

Último (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

Neuerungen in JavaServer Faces 2.0

  • 1. What‘s new in JavaServer Faces (JSF2) PAVONE AG Kai Jemella - Consultant Business & IT-Services -
  • 2. What is new in JSF 2.0 Configuration Facelets View Declaration Language / Templates Facelets Composite Components Validation State Saving / System Events / Behaivor GET Support / Navigation / Scopes Resource Loading / Error Handling Ajax
  • 3. Configuration – Annotations JSF 1.2 : faces-config.xml <managed-bean> <managed-bean-name>foo</managed-bean-name> <managed-bean-class>com.foo.Foo</managed-bean-class> <managed-bean-scope>session</managed-bean> </managed-bean> JSF 2.0 : Managed Bean Annotation @ManagedBean @SessionScoped public class Foo { }
  • 4. Configuration – Annotations JSF 2.0 : Component Annotations @FacesComponent @FacesRenderer @FacesConverter @FacesValidator @FacesBehavior
  • 5. Configuration faces-config.xml Order JSF 1.2: Loaded based on an order derived from the containing jar file’s name. JSF 2.0: Reference other faces-config-xml by <name> element e.g. for view- handler or phase-listener. <faces-config> <name>bar</name> </faces-config> <faces-config> <name>foo</name> <ordering> <after> <name>bar</name> </after> </ordering> </faces-config> <faces-config> <name>foobar</name> <ordering> <before> <others/> </before> </ordering> </faces-config>
  • 6. Configuration - Notice Notice that even if we are using JSF 2.0, we still need the Facesconfig.xml file. Annotations and the implicit navigation allow us to write an application without needing a faces-config.xml fille. but there are still cases where the configuration file is needed. Localization information, advanced features such as ELResolvers, PhaseListeners, or artifacts that rely on the decorator pattern still require a faces-config.xml file. (JSF 2.0 Cookbook, Anghel Leonard, PACKT PUBLISHING)
  • 7. What is new in JSF 2.0 Configuration Facelets View Declaration Language / Templates Facelets Composite Components Validation State Saving / System Events / Behaivor GET Support / Navigation / Scopes Resource Loading / Error Handling Ajax
  • 8. Improving JSF by Dumping JSP Several JSF Alternatives to JSP Apache Shale’s Clay JSF Templating Facelets JSF 2.0: addresses this by ViewDeclarationLanguage allows frameworks to define their own view declaration language Standard non JSP view declaration language Facelets 2.0 (should be very familiar to Facelets 1.x) Facelets View Declaration Language / Templates
  • 9. Facelets View Declaration Language / Templates JSP <@ taglib uri="http://java.sun.com/jsf/html" prefix="h"> <@ taglib uri="http://java.sun.com/jsf/core" prefix="f"> <html> <head><title>Show Customer</title></head> <body> <f:view> <h1><h:outputText value="Show Customer"/></h1> <!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:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"> <head><title>Show Customer</title></head> <body> <h1><h:outputText value="Show Customer"/></h1> Facelets
  • 10. Facelets View Declaration Language / Templates Template html <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets"> <head>…</head> <body> <div id="header"> <ui:insert name="header"><h1>MyGourmet</h1></ui:insert> <div id="content"><ui:insert name="content"/></div> </div> </body></html> <body> <ui:composition template="template.xhtml"> <ui:define name="content"> <h2>Customer</h2> <h:panelGrid id="grid" columns="2"> <h:outputText value="Given name"/> <h:outputText value="#{customer.givenName}"/> <h:outputText value="Lastname" /> <h:outputText value="#{customer.lastName}"/> </h:panelGrid> </ui:define> </ui:composition> </body> Facelet
  • 11. Facelets View Declaration Language / Templates Multiple templates <ui:composition template="template.xhtml"> ... <ui:define name="left_sidebar"> <ui:decorate template="sideBox.xhtml"> <ui:param name="title" value="Messages"/> <h:outputText value="#{bean.msg}"/> </ui:decorate> </ui:define> ... </ui:composition>
  • 12. What is new in JSF 2.0 Configuration Facelets View Declaration Language / Templates Facelets Composite Components Validation State Saving / System Events / Behaivor GET Support / Navigation / Scopes Resource Loading / Error Handling Ajax
  • 13. Facelets Composite Components Simplifies custom component development JSF 2.0: Create Components with a single file without Java First create tag library xml file and declare it in web.xml <facelet-taglib> <namespace>http://www.my.facelets.component.com/jsf</namespace> <tag> <tag-name>sayhello</tag-name> <source>sayhello.xhtml</source> </tag> </facelet-taglib> <context-param> <param-name>javax.faces.FACELETS_LIBRARIES</param-name> <param-value>/WEB-INF/facelets/tags/mycomponents.xml</param-value> </context-param>
  • 14. Facelets Composite Components Composite Component <!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:composite="http://java.sun.com/jsf/composite"> <head>…</head> <body> <composite:interface> <composite:attribute name="who"/> </composite:interface> <composite:implementation> <h:outputText value="Hello, #{cc.attrs.who}!"/> </composite:implementation> </body> </html> Use Component <html … xmlns:mycomp="http://java.sun.com/jsf/composite/greet"> <mycomp:sayhello who="World"/> </html>
  • 15. Facelets Composite Components Think LEGOs Passing sub-elements to compsition components Passing actions to composition components Insert facets, adding children, attaching listeners, validators, … Mixing JSF and Dojo widget for custom components
  • 16. What is new in JSF 2.0 Configuration Facelets View Declaration Language / Templates Facelets Composite Components Validation State Saving / System Events / Behaivor GET Support / Navigation / Scopes Resource Loading / Error Handling Ajax
  • 17. Validation JSF 2.0: Bean Validation built-in integration with JSR-303 constraints. <!-- provides bean validation --> <f:validateBean> <!-- provides required field validation --> <f:validateRequired> <!-- provides regular expression-based validation --> <f:validateRegexp> JSF 2.0: Additional Validation tags
  • 18. Validation – Bean Validation JSF 2.0: Bean Validation Annotation public class FooBar { @NotNull @Min(value = 1000) @Max(value = 99999) private Integer foo; @NotNull private String bar; } JSF 2.0: Bean Validation JSR-303 custom validator and constraints @Constraint(validatedBy = FooBarValidator.class) … public @interface FooBar { … } public class FooBarValidator implements ConstraintValidator<FooBar, Date> { … }
  • 19. Validation – Bean Validation JSF 2.0: Bean Validation Groups public interface usersIdsGroup {} public interface usersCredentialsGroup {} public userBean{ @NotEmpty(message = "The name cannot be empty!", groups = beans.usersIdsGroup.class) private String name; @Size(min = 5, max = 20, message = "You …", groups = beans. usersCredentialsGroup.class) private String password; JSF 2.0: validationGroups <f:validateBean validationGroups="beans.usersIdsGroup, otherGroup"> <h:outputText value="Name:"/> <h:inputText value="#{userBean.name}"/> </f:validateBean>
  • 20. Validation Annotations @AssertFalse // check element is false @AssertTrue // check element is true @DecimalMax // check number lower or equal @DecimalMin // check number higher or equal @Digits // check number digits and fraction @Future // check date is in the future @Max // check less than or equal @Min // check higher than or equal @NotNull // check not null @Null // check null @Valid // validation by associated object @Past // check date is in the past @Pattern // check by pattern @Size // check size ist between min and max //not in bean validation specification -> hibernate validator @Length, @NotEmpty, @ Email, @Range
  • 22. What is new in JSF 2.0 Configuration Facelets View Declaration Language / Templates Facelets Composite Components Validation State Saving / System Events / Behaivor GET Support / Navigation / Scopes Resource Loading / Error Handling Ajax
  • 23. State Saving JSF 2.0: new State Saving Problem size of the saved state can be large Component developers can now use PartialStateHolder and StateHelper Save only modified state since view initially created
  • 24. System Events JSF 2.0 new SystemEvents Global SystemEvents Application initialization / destruction Component System Events Component added to view Component rendered Component validated <h:inputText> <f:event type="preValidate«  listener="#{bean.doSomePreValidation}"/> </h:inputText>
  • 25. Behaivor JSF 2.0 new class ClientBehavior, ClientBehaivorHolder e.g. AjaxBehavior f:ajax Enhancing client-side of components Prevent hand-conding scripts and manually wiring these scripts <h:commandButton> <!--First ask for confirmation --> <foo:confirm event="click"/> <!-- If successful, send an Ajax request --> <f:ajax event="click"/> </h:commandButton>
  • 26. Behaivor JSF 2.0 confirm behaivor @FacesBehavior("foo.behavior.Confirm") public class ConfirmBehavior extends ClientBehaviorBase { @Override public String getScript( ClientBehaviorContext behaviorContext) { return "return confirm('Are you sure?')"; } }
  • 27. Behaivor JSF 2.0 Append Behavior in taglib <?xml version='1.0' encoding='UTF-8'?> <facelet-taglib xmlns="http://java.sun.com/xml/ns/javaee" version="2.0"> <namespace>http://example.org/foo</namespace> <tag> <tag-name>confirm</tag-name> <behavior> <behavior-id>foo.behavior.Confirm</behavior-id> </behavior> </tag> </facelet-taglib>
  • 28. What is new in JSF 2.0 Configuration Facelets View Declaration Language / Templates Facelets Composite Components Validation State Saving / System Events / Behaivor GET Support / Navigation / Scopes Resource Loading / Error Handling Ajax
  • 29. Navigation Conditional navigation for pre-condition <navigation-rule> <from-view-id>/foo.xhtml</from-view-id> <navigation-case> <from-outcome>success</from-outcome> <to-view-id>/bar.xhtml</to-view-id>^ <if>#{foo.someCondition}</if> </navigation-case> </navigation-rule> Reduce navigation related grunch code Implicit navigation e.g. action outcome corresponds to a view id ConfigurableNavigationHandler (available navigation rules/cases) Dynamically control the application flow
  • 30. GET Support <f:metadata> <f:viewParam name="foo" value="#{bean.foo}" required="true" requiredMessage="This parameter is a must!"/> <!-- PreRenderViewEvent --> <f:event type="preRenderView" listener="#{bean.doSomething}"/> </f:metadata> JSF 1.2: value processing of values via HTTP Post JSF 2.0: view parameters for HTTP e.g. page1.xhtml?foo=bar <h:link outcome="success" includeViewParams="true"> <f:param name="foo" value="bar"/> </h:link> JSF 2.0: view parameter inverse mapping and manual parameter
  • 31. Scopes JSF 2.0: view scope „longer than request, shorter than session“ Until the user finishes interaction with the current view UIViewRoot.getViewMap() or EL #{viewScope} JSF 2.0: flash scope Concept from Rails Short-lived conversation State survives a redirect e.g. page2?faces-redirect=true ExternalContext.getFlash() or EL #{flash} JSF 2.0: Custom Scopes to place managed beans into custom scope
  • 32. What is new in JSF 2.0 Configuration Facelets View Declaration Language / Templates Facelets Composite Components Validation State Saving / System Events / Behaivor GET Support / Navigation / Scopes Resource Loading / Error Handling Ajax
  • 33. Resource Loading / Error Handling JSF 2.0: @ResourceDependency @ResourceDependency(name="my.css",library="libus") public class MyComponent extends UIComponentBase { … } JSF 2.0: ResourceHandler e.g. images, JavaScript, stylesheets, … /resources/css/foobar.css /resources/images/foobar.jpg /resources/javascript/foobar.js <h:graphicImage library="images" name=“foobar.jpg"/> <h:outputStylesheet library="css" name=“foobar.css"/> <h:outputScript library="javascript" name=“foobar.js” target="head"/> <!-- via EL --> <h:graphicImage value="#{resource['images:foobar.jpg']}"/>
  • 34. Resource Loading / Error Handling JSF 2.0: ExceptionHandler API (central excpetion handling) <error-page> <exception-type>java.lang.NumberFormatException</exception-type> <location>/faces/error.xhtml</location> </error-page>
  • 35. What is new in JSF 2.0 Configuration Facelets View Declaration Language / Templates Facelets Composite Components Validation State Saving / System Events / Behaivor GET Support / Navigation / Scopes Resource Loading / Error Handling Ajax
  • 36. Ajax JSF 2.0 (2009) four years since Ajax was coined. JSF Ajax problem has been solved many times! Many JSF/Ajax frameworks available. DynamicFaces, RichFaces, ajax4jsf, PrimeFaces, MyFaces Tomahawk … Problem cross-framework compatibility Isn‘t it time to Ajax without 3rd party frameworks?
  • 37. Ajax Partial View Processing and Pratial View Rendering (IBM: http://www.ibm.com/developerworks/library/j-jsf2/)
  • 38. Ajax JSF 2.0: Ajax Parameter javax.faces.partial.ajax javax.faces.source javax.faces.partial.execute javax.faces.partial.render
  • 39. Ajax JSF 2.0: JavaScript API <h:form id="formID" prependId="false"> <h:outputScript name="jsf.js" library="javax.faces" target="head" /> <h:outputText id="randomID" value="#{random.random}" /> <h:commandButton id="buttonID" value="Random" onclick="jsf.ajax.request(this, event, {execute: this.id, render: 'randomID'}); return false;" /> </h:form>
  • 40. Ajax JSF 2.0: f:ajax tag <h:form id="formID" prependId="false"> <h:outputText id="randomID" value="#{random.random}" /> <h:commandButton id="buttonID" value="Random"> <f:ajax execute="formID:buttonID formID:randomID" render="formID:randomID" /> </h:commandButton> </h:form>
  • 41. Ajax Keywords Keyword Execute Render @all Every component on the page is submitted and processed. This is useful when you want to do a full- page submit. Every component on the page is rendered. This is useful when you just want to rere nder the whole page asynchronously. E.g. update client side state outside of JSF. @none Execute the lifedycle, including ist phase listeners, but no components will be traversed. Perform the Render Response phase, including firing any preRenderView events, but don‘t actually render anything. @this Submit and process only the component to which the <f:ajax> is applied. Render only the component to which the <f:ajax> is applied @form Submit and process the entire <h:form> in which the component thas has the <f:ajax> is nested. Render the entire <h:form> in which the component thas has the <f:ajax> is nested. (JavaServer faces 2.0: the complete reference By Ed Burns, Neil Griffin, Chris Schalk)
  • 42. Resources JSF Specification http://jcp.org/aboutJava/communityprocess/final/jsr314/index.html Andy Schwartz http://andyschwartz.wordpress.com/2009/07/31/whats-new-in-jsf-2/ Irian http://jsfatwork.irian.at/book_de/ IBM Developerworks http://www.ibm.com/developerworks/java/library/j-jsf2fu2/index.html JSF 2.0 Cookbook, Anghel Leonard, PACKT PUBLISHING JavaServer faces 2.0: the complete reference By Ed Burns, Neil Griffin, Chris Schalk