Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
16-11-09 JSF 2 and beyond: Keeping progress coming Andy Schwartz -  Oracle Corporation Dan Allen & Pete Muir -  Red Hat, I...
16-11-09 See how far JSF 2 has come, explore the community’s role and take a glimpse at JSF 2.next Goals
16-11-09 Join in! Twitter hashtag:  #jsf2next
16-11-09 Join in! JSF 2 and beyond: BOF Tonight @ 20:00 in Room 2!
16-11-09 Andy Schwartz <ul><li>Software engineer at  Oracle Corporation </li></ul><ul><li>Architect on ADF Faces project t...
16-11-09 Pete Muir <ul><li>Principal Software Engineer at  Red Hat, Inc </li></ul><ul><li>Seam and Weld (JSR-299 RI) proje...
16-11-09 Dan Allen <ul><li>Senior Software Engineer at  Red Hat, Inc </li></ul><ul><li>Author of Seam in Action </li></ul>...
16-11-09 Many  faces  of JSF 2 Andy  Schwartz Dan Allen Jacob Hookom Alexandr Smirnov Ken Paulsen Martin Marinschek Matthi...
Topic areas <ul><li>View </li></ul><ul><ul><li>Facelets and VDL </li></ul></ul><ul><ul><li>Ajax & behaviors </li></ul></ul...
16-11-09 View declaration Facelets, View Declaration Language API
16-11-09 The problem
16-11-09 JSP pain points <ul><li>Content vs component tree creation </li></ul><ul><li>Grunge </li></ul><ul><li>Tag class <...
16-11-09 The solution Facelets (Thanks, Jacob!)
16-11-09 Breaking free with Facelets <ul><li>View definition optimized for JSF </li></ul><ul><li>XHTML + tags (no scriptle...
16-11-09 The problem revisited But, Facelets isn’t standard :(
16-11-09 The solution revisited Now it  is !
16-11-09 The solution 2.0 <ul><li>JSF 2.0 includes Facelets in the spec </li></ul><ul><li>Same features, some enhancements...
16-11-09 View Declaration Language API <ul><li>Common infrastructure for VDLs </li></ul><ul><li>Encapsulates tree building...
16-11-09 Facelets and VDL: JSF2.next <ul><li>Facelets XHTML vs. XML </li></ul><ul><li>XSD for Facelets </li></ul><ul><li>F...
16-11-09 Component development Java components, composite components
16-11-09 The problem Component development is hard!
16-11-09 The problem in detail <ul><li>Too many artifacts </li></ul><ul><li>UIComponent class </li></ul><ul><li>Renderer c...
16-11-09 The solution: Take 1 Simplify Java component development
16-11-09 The solution: Take 1 <ul><li>Annotations replace  faces-config.xml </li></ul><ul><li>Default handlers replace tag...
16-11-09 The solution: Take 2 Composite components!
16-11-09 Composite components <ul><li>Easy component creation (via Facelets) </li></ul><ul><li>It's not just for JSF gurus...
16-11-09 Composite component definition <ul><li><composite:interface> </li></ul><ul><li>defines tool/runtime metadata </li...
Composite component definition 16-11-09 <composite:interface> <composite:attribute  name = &quot;name&quot;   default = &q...
Composite component usage 16-11-09 <html   xmlns = &quot;http://www.w3.org/1999/xhtml&quot; xmlns:h = &quot;http://java.su...
16-11-09 Composite components <ul><li>Definitions live in web root or JAR </li></ul><ul><li>Optional Java/Groovy backing f...
16-11-09 Component development: JSF2.next <ul><li>Possible to simplify further? </li></ul><ul><li>Hybrid tag libraries (co...
16-11-09 Ajax jsf.ajax.request(), <f:ajax>, Ajax Java APIs, and tree visiting
16-11-09 The problem JSF/Ajax Overload!
16-11-09 Where things went wrong <ul><li>Everyone has a solution </li></ul><ul><li>No two solutions are compatible </li></...
16-11-09 The solution Standard Ajax APIs
16-11-09 The solution in detail <ul><li>Start with a programmatic API </li></ul><ul><li>jsf.ajax.request() </li></ul><ul><...
16-11-09 jsf.ajax.request() <ul><li>Java EE's  first  JavaScript API! </li></ul><ul><li>Performs a partial page update </l...
jsf.ajax.request() 16-11-09 <h:outputScript  name = &quot;jsf.js&quot;   library = &quot;javax.faces&quot; /> ... <h:comma...
16-11-09 <f:ajax> <ul><li>Declarative mapping for  jsf.ajax.request() </li></ul><ul><li>Attach via nesting or wrapping </l...
<f:ajax> nesting 16-11-09 <h:commandButton  value = &quot;Do something Ajaxy&quot; > <f:ajax  render = &quot; out &quot; /...
<f:ajax> wrapping 16-11-09 <f:ajax  render = &quot; out &quot; /> <h:commandButton  value = &quot;Do something Ajaxy&quot;...
<f:ajax> client events 16-11-09 <h:commandButton> <f:ajax  event = &quot;mouseover&quot; /> </h:commandButton> ... <h:inpu...
16-11-09 Ajax Java APIs <ul><li>AjaxBehavior </li></ul><ul><li>PartialViewContext </li></ul><ul><li>Read/write access to e...
16-11-09 Ajax: JSF2.next <ul><li>Ajax debugging </li></ul><ul><li>Fallback </li></ul><ul><li>Id round-tripping </li></ul><...
16-11-09 Behaviors ClientBehavior, ClientBehaviorHolder
16-11-09 The problem It’s not just about Ajax
16-11-09 Think bigger <ul><li>Avoid tight coupling </li></ul><ul><li>Allow arbitrary behaviors </li></ul><ul><li>Allow arb...
16-11-09 The solution New contract: separate behavior from component
16-11-09 ClientBehavior API <ul><li>New type of attached object </li></ul><ul><li>Like converter, validator </li></ul><ul>...
ClientBehavior sample 16-11-09 @FacesBehavior ( &quot;org.demo.behavior.Greet&quot; ) public class  GreetBehavior  extends...
ClientBehavior sample 16-11-09 <h:commandButton  value = &quot;Do something Ajaxy&quot; > <f:ajax/> </h:commandButton> <h:...
16-11-09 What else is possible? <ul><li>Client-side validation </li></ul><ul><li>DOM manipulation </li></ul><ul><li>Toolti...
16-11-09 ClientBehaviorHolder API <ul><li>Contract by which behaviors are attached </li></ul><ul><li>Remember  EditableVal...
16-11-09 ClientBehaviorHolder API <ul><li>UIComponentBase has  base support </li></ul><ul><li>Implemented by all standard ...
16-11-09 Behaviors: JSF2.next <ul><li>Other standard client behaviors? </li></ul><ul><li>Other categories of behaviors? </...
16-11-09 State saving Partial state saving, state helper
16-11-09 The problem State saving is nasty
16-11-09 public  Object saveState(FacesContext ctx) { if ( _values  ==  null ) { _values  =  new  Object[10]; } _values [0...
16-11-09 Another problem State saving is expensive
16-11-09 State overhead <ul><li>State saving == component developer tax </li></ul><ul><li>Do I really need to implement sa...
16-11-09 The solution Partial state saving for smaller state. State helper utilites for happier component developers.
16-11-09 Partial state saving <ul><li>Why save the full component tree? </li></ul><ul><li>Initial component tree is access...
16-11-09 Partial state saving <ul><li>Build the component tree </li></ul><ul><li>Lock it down (mark initial state) </li></...
16-11-09 State saving 2.0 <ul><li>PartialStateHolder </li></ul><ul><li>StateHolder that can lock down state </li></ul><ul>...
16-11-09 State saving: JSF2.next <ul><li>Further optimizations? </li></ul><ul><li>Better support for edge cases </li></ul>...
16-11-09 Controller GET support, bookmarkable URLs, navigation and redirects, and resource loading
16-11-09 GET support View metadata, view parameters, pre-render event listeners and bookmarkable URL components
Consuming 16-11-09 http://acme.org/catalog.jsf?page=2  http://acme.org/item.jsf?id=4
Initial request lifecycle 16-11-09 http://acme.org/catalog.jsf?cat=electronics&page=3&layout=grid
Initial data 16-11-09 http://acme.org/ catalog.jsf ?cat=electronics&page=3&layout=grid view ID /catalog.xhtml
Initial data 16-11-09 http://acme.org/catalog.jsf? cat=electronics&page=3&layout=grid request parameters cat=electronics p...
Bean property mapping 16-11-09 <managed-bean> ... <managed-bean-property> <property-name> category </property-name> <value...
16-11-09 Bean property mapping limitations <ul><li>Assignment occurs when bean is used </li></ul><ul><li>What if mapping d...
16-11-09 View metadata <ul><li>Yet another XML schema? (YAXS!) </li></ul><ul><li>Need elements for: </li></ul><ul><li>matc...
Reuse the tree 16-11-09
View metadata facet 16-11-09 <f:view> <f:metadata> ... </f:metadata> ... </f:view>
16-11-09 View metadata facet <ul><li>Built-in facet of UIViewRoot </li></ul><ul><li>Known place to find metadata </li></ul...
16-11-09 View metadata lifecycle <ul><li>Initial request is now a full postback </li></ul><ul><li>UI component tree only c...
View parameter 16-11-09 <f:view> <f:metadata> <f:viewParam name=&quot;cat&quot; value=&quot;#{catalogBean.category}&quot;/...
View parameter w/ converter 16-11-09 <f:view> <f:metadata> <f:viewParam  name = &quot;cat&quot;   value = &quot;#{catalogB...
16-11-09 View parameter assignment <ul><li>name  – request parameter name </li></ul><ul><li>value  – bean property describ...
View metadata templating 16-11-09 <f:view> <f:metadata> <ui:include   src = &quot;/WEB-INF/metadata/catalog.xhtml&quot; />...
16-11-09 Post-processing The values are set, now what?
16-11-09 Component system events <ul><li>Fine-grained event system in JSF 2 </li></ul><ul><li>Publish/subscribe pattern (3...
Post-mapping event listener 16-11-09 <f:view> <f:metadata> ... <f:event   type = &quot; preRenderView &quot;   listener = ...
Hold the rendering! 16-11-09 public void  onRender() { FacesContext ctx = FacesContext.getCurrentInstance(); if  (ctx.isVa...
Report downloads 16-11-09 <view   xmlns = &quot;http://java.sun.com/jsf/core&quot; > <event   type = &quot;preRenderView&q...
Pushing the file 16-11-09 public void  download() { FacesContext ctx = FacesContext.getCurrentInstance(); pushFile( ctx.ge...
View actions 16-11-09 <f:view> <f:metadata> ... <f:viewAction execute=&quot;#{catalogBean.onRender}&quot;/> </f:metadata> ...
View actions 16-11-09 <navigation-rule> <from-view-id> /catalog.xhtml </from-view-id> <navigation-case> <from-action> #{ca...
16-11-09 View actions vs PreRenderView <ul><li>It’s about timing </li></ul><ul><li>PreRenderView </li></ul><ul><li>Execute...
How do we process this URL? 16-11-09 http://acme.org/catalog/category/electronics
Pretty URLs 16-11-09 <rewrite-rule> <rewrite-view-id> /catalog.xhtml </rewrite-view-id> <rewrite-case> <url-pattern> /cata...
Producing 16-11-09
16-11-09 UIOutputLink <ul><li>Basic hyperlink-generating component </li></ul><ul><li>Not aware of: </li></ul><ul><li>conte...
16-11-09 UIOutcomeTarget <ul><li>Intelligent  hyperlink-generating component </li></ul><ul><li>Aware of: </li></ul><ul><li...
Generating bookmarkable links 16-11-09 <h:link   value = &quot;Previous&quot;   includeViewParams = &quot;true&quot; > <f:...
16-11-09 GET support: JSF 2.next <ul><li>View actions –  <f:viewAction> </li></ul><ul><li>View restrictions –  <f:restrict...
16-11-09 Navigation Implicit, conditional and preemptive navigation, queryable navigation rules and redirect parameters
16-11-09 Implicit navigation <ul><li>Fall-through case catering to prototypes </li></ul><ul><li>Logical outcome => view ID...
16-11-09 Tweaking implicit navigation <ul><li>Can include query string </li></ul><ul><li>/product.xhtml ?id=3 </li></ul><u...
A navigation shorthand 16-11-09 <h:commandButton   action = &quot;#{productBean.save}&quot;   value = &quot;Save&quot; /> ...
A navigation short (er) hand 16-11-09 Can link to navigation case later <h:commandButton   action = &quot;#{productBean.sa...
16-11-09 Logical outcomes aren’t logical <ul><li>Leak into business logic </li></ul><ul><li>Reuse is difficult </li></ul><...
16-11-09 Conditional navigation <ul><li>Navigation case matched based on state </li></ul><ul><li>Promotes loose coupling <...
A conditional case 16-11-09 <navigation-case> <from-action> #{registration.register} </from-action> <if>#{currentUser.regi...
Matching a void outcome 16-11-09 <navigation-case> <from-action> #{catalog.search} </from-action> <if>#{true}</if> <to-vie...
16-11-09 Preemptive navigation <ul><li>Evaluated at render time </li></ul><ul><li>Outcome translated into bookmarkable URL...
Bookmarkable link 16-11-09 <h:link   outcome = &quot;product&quot;   value = &quot;View&quot; > <f:param   name = &quot;id...
16-11-09 Redirect parameters <ul><li>No support in JSF 1.x </li></ul><ul><li>Made redirect after POST difficult </li></ul>...
Redirect after POST the  hard  way 16-11-09 FacesContext ctx = FacesContext.getCurrentInstance(); ExternalContext extCtx =...
Redirect after POST the  easier  way 16-11-09 <navigation-case> <from-action> #{productBean.save} </from-action> <if> #{pr...
Redirect after POST the  best  way 16-11-09 <navigation-case> <from-action> #{productBean.save} </from-action> <if> #{prod...
16-11-09 Navigation: JSF 2.next <ul><li>Include view parameters automatically </li></ul><ul><li><if>#{true}</if>  is  ugly...
16-11-09 Resource handling Native resource handling, packaging and resource relocation
16-11-09 No more  “bonus”  servlet!
16-11-09 Resource handling <ul><li>Load resources out of web root or JAR </li></ul><ul><li>Associate resources with UIComp...
Declarative component resources 16-11-09 @ResourceDependency ( name =  &quot;jsf.js&quot; , library =  &quot;javax.faces&q...
16-11-09 A resource at a glance <ul><li>Structure </li></ul><ul><li>Name </li></ul><ul><li>Library </li></ul><ul><li>Local...
16-11-09 A third request processing scenario
16-11-09 Resolving a resource <ul><li>Served from web root </li></ul><ul><li><h:graphicImage  name = &quot;visa.png&quot; ...
16-11-09 Resource relocation <ul><li>Resources can target section of document </li></ul><ul><li>Essential for templating <...
16-11-09 Resources: JSF 2.next <ul><li>Sprite generation </li></ul><ul><li>Compression support </li></ul><ul><li>What else...
16-11-09 Model Java EE 6 component model, Bean Validation, error handling and resource loading
16-11-09 Java EE 6: Goals <ul><li>Extensibility </li></ul><ul><li>Allow more components to be standalone (EJB 3.1) </li></...
16-11-09 Java EE 6: Newcomers <ul><li>Managed Beans (part of  JSR-316 ) </li></ul><ul><li>Contexts and Dependency Injectio...
16-11-09 Java EE 6: Notable updates <ul><li>Servlet 3.0 </li></ul><ul><li>JPA 2.0 </li></ul><ul><li>Type-safe Criteria API...
16-11-09 Web profile contents <ul><li>Persistence </li></ul><ul><li>JPA 2.0 </li></ul><ul><li>JTA </li></ul><ul><li>Compon...
16-11-09 JSR-299: Essential ingredients <ul><li>Beans types </li></ul><ul><li>Qualifier annotations </li></ul><ul><li>Scop...
Simple example 16-11-09 public class  Hello {  public  String sayHello(String name) {  return   &quot;Hello, &quot;  + nam...
Simple example 16-11-09 public class  Printer { @Inject  Hello  hello ; public  void printHello() {  System.out.println( h...
Constructor injection 16-11-09 public class  Printer {  private  Hello  hello ;  @Inject public  Printer(Hello hello) {  t...
Bean EL names 16-11-09 @Named( &quot;hello&quot; )  public class  Hello { private  String name;  // getters and setters no...
JSF view 16-11-09 <h:inputText   value = &quot;#{hello.name}&quot; /> <h:commandButton   value = &quot;Say Hello&quot;   a...
16-11-09 Qualifier An annotation that lets a client choose between multiple implementations of an API at runtime
Write a qualified implementation 16-11-09 @Casual  public class  Hi  extends  Hello {  public  String sayHello(String name...
Using a qualifier 16-11-09 public class  Printer { @Inject  @Casual  Hello  hello ; public void printHello() {  System. ou...
16-11-09 Scopes and contexts <ul><li>Built-in scopes:  </li></ul><ul><li>Any servlet request:  @ApplicationScoped ,   @Req...
16-11-09 Producer methods <ul><li>Producer methods allow control over bean creation where: </li></ul><ul><li>the objects t...
16-11-09 Parameterized EL methods <ul><li>Syntax similar to Java method calls </li></ul><ul><li>Method arguments are EL ex...
16-11-09 Validation Bean Validation integration, validating empty fields and multi-field validation with post-validate eve...
16-11-09 One model... ...validated across multiple layers Constraints in the enterprise User String username String email
16-11-09 Bean Validation (JSR-303) <ul><li>Constrain once, validate anywhere </li></ul><ul><li>Centrally define constraint...
Defining constraints on the model 16-11-09 public class  User { ... @NotNull @Size(min = 3, max = 25) public  String getUs...
16-11-09 One model... ...validated across multiple layers Constraints in JSF User String username String email
Enforcing constraints in the UI 16-11-09 <h:inputText  id = &quot;username&quot;   value = &quot;#{user.username}&quot; />...
Constraining partially 16-11-09 <h:inputText   id = &quot;username&quot;   value = &quot;#{user.username}&quot; > <f:valid...
16-11-09 The case of the empty field <ul><li>Validation skipped if value is: </li></ul><ul><li>null </li></ul><ul><li>a ze...
16-11-09 Do you mean null? <ul><li>Problem : user can’t enter null in text field </li></ul><ul><li>Side-effect : inadverte...
16-11-09 Multi-field validation <ul><li>A tougher problem than it seems </li></ul><ul><li>Two approaches: </li></ul><ul><l...
Listening for post validate 16-11-09 <h:form> <f:event type=&quot;postValidate&quot; listener=&quot;#{minMax.validate}&quo...
Validating across fields 16-11-09 @Inject  FacesContext  ctx ; private UIInput  minInput ,  maxInput ;  // accessors hidde...
16-11-09 Validation JSF.next <ul><li>What about postModelUpdate? </li></ul><ul><li>Adding FacesMessages is tedious </li></...
16-11-09 Error handling Exception handlers, exception events, servlet errors and the default error page
16-11-09 The good news No more swallowed exceptions!
16-11-09 The bad news You’re still going to get exceptions
16-11-09 Exception handler <ul><li>Hub for handling  unexpected  exceptions </li></ul><ul><li>When exception is thrown: </...
16-11-09 Default error page
16-11-09 Development diagnostics <ul><li>Activated when ProjectStage = Development </li></ul><ul><li>Report includes: </li...
<ul><li>Exceptions  servlet error handler ( web.xml ) </li></ul><ul><li>Several problems: </li></ul><ul><li>Error page is ...
Declarative error handling  in JSF 16-11-09 <exception  class = &quot;javax.persistence.EntityNotFoundException&quot; > <r...
16-11-09 Ajax error handling <ul><li>JavaScript error callback for single request </li></ul><ul><li><f:ajax ...  onerror =...
16-11-09 Pain relief Select items from collections, validation failed flag, API improvements, varStatus on ui:repeat, and ...
From collection to select items 16-11-09 <h:selectOneMenu  value = &quot;#{product.category}&quot; > <f:selectItems  value...
16-11-09 Minor improvements that add up <ul><li>Retrieve faces messages as java.util.List </li></ul><ul><li>FacesContext.g...
16-11-09 Pain relief: JSF 2.next <ul><li>UIData components </li></ul><ul><li>java.util.Collection </li></ul><ul><li>varSta...
16-11-09 Community JSR-314-OPEN mailinglist, javaserverfaces-spec-public project, JCP.org and  you !
16-11-09 Steps towards openness <ul><li>Semi- public  mailinglist – JSR-314-OPEN </li></ul><ul><li>http://archives.java.su...
16-11-09 Next steps <ul><li>Anonymous read access  to JSR-314-OPEN </li></ul><ul><li>Allow community to follow along </li>...
16-11-09 Creating a JCP.org profile Did you know that anyone can have a JCP.org profile? Just sign up!
16-11-09 JCP.org 2.0 - Launched June 2009 <ul><li>Goals are to enhance: </li></ul><ul><li>participation, </li></ul><ul><li...
16-11-09 Becoming a JCP member Did you know that anyone can become a JCP member?  Just sign the JSPA!
16-11-09 JCP membership fee (JSPA) <ul><li>Commercial organizations:  $5000 </li></ul><ul><li>Educational/non-profit organ...
16-11-09 Membership benefits <ul><li>Submit JSRs </li></ul><ul><li>Serve on a JSR Expert Group (EG) </li></ul><ul><li>Vote...
16-11-09 JSF community home page <ul><li>Single entry point into the JSF ecosystem: </li></ul><ul><li>Specification and AP...
16-11-09 Summary <ul><li>JSF 2 is a drastic improvement </li></ul><ul><li>Embraced de-facto community standards </li></ul>...
16-11-09 See you at the JSF 2 BOF! (20:00) <ul><li>Learn </li></ul><ul><li>http://tinyurl.com/ jsf2new </li></ul><ul><li>h...
Upcoming SlideShare
Loading in …5
×

JSF 2 and beyond: Keeping progress coming

11,368 views

Published on

Covers new features in JSF 2, community involvement in JSF and a look towards the future of this framework.

Presented by Dan Allen, Pete Muir and Andy Schwartz at Devoxx 2009.

http://www.devoxx.com/display/DV09/JSF+2+and+beyond

Published in: Technology
  • Be the first to comment

JSF 2 and beyond: Keeping progress coming

  1. 1. 16-11-09 JSF 2 and beyond: Keeping progress coming Andy Schwartz - Oracle Corporation Dan Allen & Pete Muir - Red Hat, Inc.
  2. 2. 16-11-09 See how far JSF 2 has come, explore the community’s role and take a glimpse at JSF 2.next Goals
  3. 3. 16-11-09 Join in! Twitter hashtag: #jsf2next
  4. 4. 16-11-09 Join in! JSF 2 and beyond: BOF Tonight @ 20:00 in Room 2!
  5. 5. 16-11-09 Andy Schwartz <ul><li>Software engineer at Oracle Corporation </li></ul><ul><li>Architect on ADF Faces project team </li></ul><ul><li>Member of the JSR-314 (JSF 2) Expert Group </li></ul>http://andyschwartz.wordpress.com
  6. 6. 16-11-09 Pete Muir <ul><li>Principal Software Engineer at Red Hat, Inc </li></ul><ul><li>Seam and Weld (JSR-299 RI) project lead </li></ul><ul><li>Member of the JSR-314 (JSF 2) Expert Group </li></ul>http://in.relation.to/Bloggers/Pete
  7. 7. 16-11-09 Dan Allen <ul><li>Senior Software Engineer at Red Hat, Inc </li></ul><ul><li>Author of Seam in Action </li></ul><ul><li>Seam and Weld project member </li></ul><ul><li>Member of the JSR-314 (JSF 2) Expert Group </li></ul>http://mojavelinux.com
  8. 8. 16-11-09 Many faces of JSF 2 Andy Schwartz Dan Allen Jacob Hookom Alexandr Smirnov Ken Paulsen Martin Marinschek Matthias Wess endorf Pete Muir Alexander Jesse Imre O ßwald Yara Senger Lincoln Baxter Adam Winer Craig McClanahan Kito Mann Rick Hightower Joe Ottinger Ted Goddard Neil Griffin Jason Lee Stan Silvert David Geary Micheal Freedman Hazem Saleh Çağata Çivici Dennis Byrne Roger Keays Amy Fowler Max Katz Jeremy Grelle Keith Donald Emmanuel Bernard Ed Burns Jim Driscoll Roger Kitain Ryan Lubke Nick Belaevski Gavin King
  9. 9. Topic areas <ul><li>View </li></ul><ul><ul><li>Facelets and VDL </li></ul></ul><ul><ul><li>Ajax & behaviors </li></ul></ul><ul><ul><li>Components & state saving </li></ul></ul><ul><li>Controller </li></ul><ul><ul><li>“Bookmarkability” </li></ul></ul><ul><ul><li>Navigation </li></ul></ul><ul><ul><li>Resource loading </li></ul></ul>16-11-09 <ul><li>Model </li></ul><ul><li>Components and EL </li></ul><ul><li>Validation </li></ul><ul><li>Error handling </li></ul><ul><li>Pain relief </li></ul><ul><li>Community </li></ul>(Andy) (Dan) (Pete) (Dan)
  10. 10. 16-11-09 View declaration Facelets, View Declaration Language API
  11. 11. 16-11-09 The problem
  12. 12. 16-11-09 JSP pain points <ul><li>Content vs component tree creation </li></ul><ul><li>Grunge </li></ul><ul><li>Tag class </li></ul><ul><li>Tag library </li></ul><ul><li>Mixing presentation with logic </li></ul><ul><li>Translation/compilation </li></ul><ul><li>Stateful tags </li></ul>
  13. 13. 16-11-09 The solution Facelets (Thanks, Jacob!)
  14. 14. 16-11-09 Breaking free with Facelets <ul><li>View definition optimized for JSF </li></ul><ul><li>XHTML + tags (no scriptlets) </li></ul><ul><li>Default, stateless tag handling </li></ul><ul><li>Simplified tag library configuration </li></ul><ul><li>No more translation/compilation </li></ul><ul><li>Templating </li></ul>
  15. 15. 16-11-09 The problem revisited But, Facelets isn’t standard :(
  16. 16. 16-11-09 The solution revisited Now it is !
  17. 17. 16-11-09 The solution 2.0 <ul><li>JSF 2.0 includes Facelets in the spec </li></ul><ul><li>Same features, some enhancements </li></ul><ul><li>Facelets is now preferred over JSP </li></ul><ul><li>Most new functionality not available in JSP </li></ul><ul><li>Also new : View Declaration Language APIs </li></ul>
  18. 18. 16-11-09 View Declaration Language API <ul><li>Common infrastructure for VDLs </li></ul><ul><li>Encapsulates tree building, state saving </li></ul><ul><li>Encourage innovation in VDL space </li></ul><ul><li>JSF Templating </li></ul><ul><li>Gracelets </li></ul><ul><li>Any other ideas? </li></ul>
  19. 19. 16-11-09 Facelets and VDL: JSF2.next <ul><li>Facelets XHTML vs. XML </li></ul><ul><li>XSD for Facelets </li></ul><ul><li>Facelets/JSP compatibility </li></ul><ul><li>Whitespace handling </li></ul><ul><li>Are Facelets APIs complete? </li></ul><ul><li>Are VDL APIs complete? </li></ul>
  20. 20. 16-11-09 Component development Java components, composite components
  21. 21. 16-11-09 The problem Component development is hard!
  22. 22. 16-11-09 The problem in detail <ul><li>Too many artifacts </li></ul><ul><li>UIComponent class </li></ul><ul><li>Renderer class </li></ul><ul><li>Tag class </li></ul><ul><li>tld </li></ul><ul><li>lots of faces-config.xml </li></ul><ul><li>Ouch ! </li></ul>
  23. 23. 16-11-09 The solution: Take 1 Simplify Java component development
  24. 24. 16-11-09 The solution: Take 1 <ul><li>Annotations replace faces-config.xml </li></ul><ul><li>Default handlers replace tag classes </li></ul><ul><li>Facelets taglib.xml replaces tld grunge </li></ul><ul><li>Simplified state saving </li></ul><ul><li>More on this in a bit... </li></ul><ul><li>Better, but good enough? </li></ul>
  25. 25. 16-11-09 The solution: Take 2 Composite components!
  26. 26. 16-11-09 Composite components <ul><li>Easy component creation (via Facelets) </li></ul><ul><li>It's not just for JSF gurus any more </li></ul><ul><li>Defined using a single Facelets file </li></ul><ul><li>No external configuration </li></ul><ul><li>Conventions define tag namespace/name </li></ul><ul><li>No Java code required </li></ul>
  27. 27. 16-11-09 Composite component definition <ul><li><composite:interface> </li></ul><ul><li>defines tool/runtime metadata </li></ul><ul><li><composite:implementation> </li></ul><ul><li>defines content and behavior </li></ul><ul><li>Composite tags for inserting children </li></ul><ul><li>Attribute access via #{cc.attrs} </li></ul><ul><li>Client id access #{cc.clientId} </li></ul>
  28. 28. Composite component definition 16-11-09 <composite:interface> <composite:attribute name = &quot;name&quot; default = &quot;World&quot; /> </composite:interface> <composite:implementation> Hello, #{cc.attrs.name}! </composite:implementation> resources/foo/greeting.xhtml
  29. 29. Composite component usage 16-11-09 <html xmlns = &quot;http://www.w3.org/1999/xhtml&quot; xmlns:h = &quot;http://java.sun.com/jsf/html&quot; xmlns:foo=&quot;http://java.sun.com/jsf/composite/foo&quot; > <body> <foo:greeting name=&quot;Devoxx&quot;/> </body> </html>
  30. 30. 16-11-09 Composite components <ul><li>Definitions live in web root or JAR </li></ul><ul><li>Optional Java/Groovy backing file </li></ul><ul><li>Optional .properties file </li></ul><ul><li>Optional supporting resources </li></ul><ul><li>Attach listeners, converters, validators, behaviors </li></ul>
  31. 31. 16-11-09 Component development: JSF2.next <ul><li>Possible to simplify further? </li></ul><ul><li>Hybrid tag libraries (composites + Java) </li></ul><ul><li>Resource location ( WEB-INF/resources ) </li></ul><ul><li>Java/Groovy backing class naming </li></ul><ul><li>Insert vs. render children </li></ul>
  32. 32. 16-11-09 Ajax jsf.ajax.request(), <f:ajax>, Ajax Java APIs, and tree visiting
  33. 33. 16-11-09 The problem JSF/Ajax Overload!
  34. 34. 16-11-09 Where things went wrong <ul><li>Everyone has a solution </li></ul><ul><li>No two solutions are compatible </li></ul><ul><li>Sad application developers </li></ul>
  35. 35. 16-11-09 The solution Standard Ajax APIs
  36. 36. 16-11-09 The solution in detail <ul><li>Start with a programmatic API </li></ul><ul><li>jsf.ajax.request() </li></ul><ul><li>Add in some declarative support </li></ul><ul><li><f:ajax> </li></ul><ul><li>Don't forget about the server side </li></ul><ul><li>PartialViewContext </li></ul><ul><li>PartialResponseWriter </li></ul>
  37. 37. 16-11-09 jsf.ajax.request() <ul><li>Java EE's first JavaScript API! </li></ul><ul><li>Performs a partial page update </li></ul><ul><li>Caller specifies execute/render ids </li></ul><ul><li>Or keywords: @all, @form, @this, @none </li></ul><ul><li>jsf.ajax.request() takes care of the rest </li></ul><ul><li>Supports notifications of events/errors </li></ul>
  38. 38. jsf.ajax.request() 16-11-09 <h:outputScript name = &quot;jsf.js&quot; library = &quot;javax.faces&quot; /> ... <h:commandButton value = &quot;Do something Ajaxy&quot; onclick = &quot;jsf.ajax.request(this, event, {render: ' out '}); return false;&quot; /> ... <h:outputText id = &quot; out &quot; value = &quot;Update me!&quot; />
  39. 39. 16-11-09 <f:ajax> <ul><li>Declarative mapping for jsf.ajax.request() </li></ul><ul><li>Attach via nesting or wrapping </li></ul>
  40. 40. <f:ajax> nesting 16-11-09 <h:commandButton value = &quot;Do something Ajaxy&quot; > <f:ajax render = &quot; out &quot; /> </h:commandButton> ... <h:outputText id = &quot; out &quot; value = &quot;Update me!&quot; />
  41. 41. <f:ajax> wrapping 16-11-09 <f:ajax render = &quot; out &quot; /> <h:commandButton value = &quot;Do something Ajaxy&quot; /> <h:commandButton value = &quot;Do something else&quot; /> <h:commandButton value = &quot;One more here&quot; /> </f:ajax> ... <h:outputText id = &quot; out &quot; value = &quot;Update me!&quot; />
  42. 42. <f:ajax> client events 16-11-09 <h:commandButton> <f:ajax event = &quot;mouseover&quot; /> </h:commandButton> ... <h:inputText> <f:ajax event = &quot;focus&quot; /> </h:commandButton>
  43. 43. 16-11-09 Ajax Java APIs <ul><li>AjaxBehavior </li></ul><ul><li>PartialViewContext </li></ul><ul><li>Read/write access to execute/render lists </li></ul><ul><li>processPartial() </li></ul><ul><li>PartialResponseWriter </li></ul><ul><li>New tree visitor API </li></ul>
  44. 44. 16-11-09 Ajax: JSF2.next <ul><li>Ajax debugging </li></ul><ul><li>Fallback </li></ul><ul><li>Id round-tripping </li></ul><ul><li>Out-of-band/GET requests </li></ul><ul><li>Event collapsing </li></ul><ul><li>File upload </li></ul>
  45. 45. 16-11-09 Behaviors ClientBehavior, ClientBehaviorHolder
  46. 46. 16-11-09 The problem It’s not just about Ajax
  47. 47. 16-11-09 Think bigger <ul><li>Avoid tight coupling </li></ul><ul><li>Allow arbitrary behaviors </li></ul><ul><li>Allow arbitrary components to participate </li></ul>
  48. 48. 16-11-09 The solution New contract: separate behavior from component
  49. 49. 16-11-09 ClientBehavior API <ul><li>New type of attached object </li></ul><ul><li>Like converter, validator </li></ul><ul><li>Attached to component by “event” </li></ul><ul><li>Contributes scripts to markup </li></ul><ul><li>Also can participate in decode </li></ul>
  50. 50. ClientBehavior sample 16-11-09 @FacesBehavior ( &quot;org.demo.behavior.Greet&quot; ) public class GreetBehavior extends ClientBehaviorBase { @Override public String getScript(ClientBehaviorContext ctx) { return &quot;alert('Hello, World!')&quot; ; } }
  51. 51. ClientBehavior sample 16-11-09 <h:commandButton value = &quot;Do something Ajaxy&quot; > <f:ajax/> </h:commandButton> <h:commandButton value = &quot;Say Hello&quot; > <foo:greet/> </h:commandButton>
  52. 52. 16-11-09 What else is possible? <ul><li>Client-side validation </li></ul><ul><li>DOM manipulation </li></ul><ul><li>Tooltips, hover content </li></ul><ul><li>Logging </li></ul><ul><li>Confirmation </li></ul><ul><li>Key handling </li></ul>
  53. 53. 16-11-09 ClientBehaviorHolder API <ul><li>Contract by which behaviors are attached </li></ul><ul><li>Remember EditableValueHolder ? </li></ul><ul><li>addClientBehavior(eventName, behavior) </li></ul><ul><li>Specifies component-specific events </li></ul><ul><li>Specifies optional default event </li></ul>
  54. 54. 16-11-09 ClientBehaviorHolder API <ul><li>UIComponentBase has base support </li></ul><ul><li>Implemented by all standard components </li></ul><ul><li>Yours can too ! </li></ul><ul><li>Renderers responsible for retrieving and rendering ClientBehavior scripts </li></ul>
  55. 55. 16-11-09 Behaviors: JSF2.next <ul><li>Other standard client behaviors? </li></ul><ul><li>Other categories of behaviors? </li></ul><ul><li>Phase behavior </li></ul><ul><li>Pre-decode behavior execution </li></ul><ul><li>Rendering utilities </li></ul>
  56. 56. 16-11-09 State saving Partial state saving, state helper
  57. 57. 16-11-09 The problem State saving is nasty
  58. 58. 16-11-09 public Object saveState(FacesContext ctx) { if ( _values == null ) { _values = new Object[10]; } _values [0] = super .saveState(ctx); _values [1] = accesskey ; _values [2] = alt ; _values [3] = dir ; _values [4] = disabled ; _values [5] = image ; _values [6] = label ; _values [7] = lang ; _values [8] = onblur ; _values [9] = onchange ; return _values ; } public void restoreState( FacesContext ctx, Object _state) { _values = (Object[]) state; super .restoreState(ctx, _values [0]); this . accesskey = (java.lang.String) _values [1]; this . alt = (java.lang.String) _values [2]; this . dir = (java.lang.String) _values [3]; this . disabled = (java.lang.Boolean) _values [4]; this . image = (java.lang.String) _values [5]; this . label = (java.lang.String) _values [6]; this . lang = (java.lang.String) _values [7]; this . onblur = (java.lang.String) _values [8]; this . onchange = (java.lang.String) _values [9]; } State saving lunacy
  59. 59. 16-11-09 Another problem State saving is expensive
  60. 60. 16-11-09 State overhead <ul><li>State saving == component developer tax </li></ul><ul><li>Do I really need to implement saveState and restoreState? </li></ul><ul><li>Full component tree state not small </li></ul><ul><li>Where do you want it? Session? Client? </li></ul>
  61. 61. 16-11-09 The solution Partial state saving for smaller state. State helper utilites for happier component developers.
  62. 62. 16-11-09 Partial state saving <ul><li>Why save the full component tree? </li></ul><ul><li>Initial component tree is accessible </li></ul><ul><li>Just need to re-execute the tags </li></ul><ul><li>Initial component tree isn't sufficient </li></ul><ul><li>Also need any state deltas. </li></ul>
  63. 63. 16-11-09 Partial state saving <ul><li>Build the component tree </li></ul><ul><li>Lock it down (mark initial state) </li></ul><ul><li>Subsequent modifications saved </li></ul><ul><li>On restore, build component tree again </li></ul><ul><li>Apply previously saved deltas </li></ul><ul><li>No need to save full state! </li></ul>
  64. 64. 16-11-09 State saving 2.0 <ul><li>PartialStateHolder </li></ul><ul><li>StateHolder that can lock down state </li></ul><ul><li>StateHelper </li></ul><ul><li>Manages state, tracks deltas </li></ul><ul><li>No more custom saveState/restoreState </li></ul><ul><li>Significantly smaller saved state! </li></ul>
  65. 65. 16-11-09 State saving: JSF2.next <ul><li>Further optimizations? </li></ul><ul><li>Better support for edge cases </li></ul><ul><li>Re-execution of tags after invoke app </li></ul><ul><li>Target high scalability cases </li></ul><ul><li>Fully stateless? </li></ul>
  66. 66. 16-11-09 Controller GET support, bookmarkable URLs, navigation and redirects, and resource loading
  67. 67. 16-11-09 GET support View metadata, view parameters, pre-render event listeners and bookmarkable URL components
  68. 68. Consuming 16-11-09 http://acme.org/catalog.jsf?page=2 http://acme.org/item.jsf?id=4
  69. 69. Initial request lifecycle 16-11-09 http://acme.org/catalog.jsf?cat=electronics&page=3&layout=grid
  70. 70. Initial data 16-11-09 http://acme.org/ catalog.jsf ?cat=electronics&page=3&layout=grid view ID /catalog.xhtml
  71. 71. Initial data 16-11-09 http://acme.org/catalog.jsf? cat=electronics&page=3&layout=grid request parameters cat=electronics page=3 layout=grid
  72. 72. Bean property mapping 16-11-09 <managed-bean> ... <managed-bean-property> <property-name> category </property-name> <value> #{param['cat']} </value> </managed-bean-property> </managed-bean>
  73. 73. 16-11-09 Bean property mapping limitations <ul><li>Assignment occurs when bean is used </li></ul><ul><li>What if mapping differs based on current view? </li></ul><ul><li>Implicit conversion only </li></ul><ul><li>What if property type is java.util.Date? </li></ul><ul><li>What about validation? </li></ul><ul><li>What about a post-mapping listener? </li></ul>Need more sophisticated, view-oriented mapping
  74. 74. 16-11-09 View metadata <ul><li>Yet another XML schema? (YAXS!) </li></ul><ul><li>Need elements for: </li></ul><ul><li>matching view ID(s) </li></ul><ul><li>describing EL binding </li></ul><ul><li>conversion </li></ul><ul><li>validation </li></ul><ul><li>post-mapping listener </li></ul><ul><li>... </li></ul>#{...}
  75. 75. Reuse the tree 16-11-09
  76. 76. View metadata facet 16-11-09 <f:view> <f:metadata> ... </f:metadata> ... </f:view>
  77. 77. 16-11-09 View metadata facet <ul><li>Built-in facet of UIViewRoot </li></ul><ul><li>Known place to find metadata </li></ul><ul><li>Can be built separate from tree </li></ul><ul><li>Reuses UI component infrastructure </li></ul><ul><li>Metadata is described using UI components </li></ul><ul><li>Manifests as UIPanel component </li></ul><ul><li>Easy to extend </li></ul>
  78. 78. 16-11-09 View metadata lifecycle <ul><li>Initial request is now a full postback </li></ul><ul><li>UI component tree only contains view metadata </li></ul><ul><li>Only happens if view parameters are present </li></ul><ul><li>A postback is just a postback </li></ul><ul><li>Metadata components just like any other UI components </li></ul>meta
  79. 79. View parameter 16-11-09 <f:view> <f:metadata> <f:viewParam name=&quot;cat&quot; value=&quot;#{catalogBean.category}&quot;/> </f:metadata> ... </f:view> UIViewParameter
  80. 80. View parameter w/ converter 16-11-09 <f:view> <f:metadata> <f:viewParam name = &quot;cat&quot; value = &quot;#{catalogBean.category}&quot; > <f:converter converterId=&quot;com.acme.converter.Category&quot;/> </f:viewParam> </f:metadata> ... </f:view> UIViewParameter
  81. 81. 16-11-09 View parameter assignment <ul><li>name – request parameter name </li></ul><ul><li>value – bean property described w/ EL </li></ul><ul><li>Specialization of UIInput </li></ul><ul><li>Initial value transfered from request parameter </li></ul><ul><li>Submitted value stored in component state </li></ul><ul><li>Request parameter can override value on postback </li></ul><ul><li>Foundation of bookmarkable URLs </li></ul>UIInput UIViewParameter
  82. 82. View metadata templating 16-11-09 <f:view> <f:metadata> <ui:include src = &quot;/WEB-INF/metadata/catalog.xhtml&quot; /> [ or ] <acme:catalogMetadata/> </f:metadata> ... </f:view> More powerful & flexible than a matching pattern
  83. 83. 16-11-09 Post-processing The values are set, now what?
  84. 84. 16-11-09 Component system events <ul><li>Fine-grained event system in JSF 2 </li></ul><ul><li>Publish/subscribe pattern (3 tiers) </li></ul><ul><li>PostAddToViewEvent </li></ul><ul><li>After component is created (e.g., UIViewRoot) </li></ul><ul><li>PreRenderViewEvent </li></ul><ul><li>Before component tree is rendered </li></ul><ul><li>| | : Lifecycle : | | if view ID is changed by listener </li></ul>
  85. 85. Post-mapping event listener 16-11-09 <f:view> <f:metadata> ... <f:event type = &quot; preRenderView &quot; listener = &quot;#{catalogBean.onRender}&quot; /> </f:metadata> ... </f:view> Declarative system event No-args method or method that accepts ComponentSystemEvent
  86. 86. Hold the rendering! 16-11-09 public void onRender() { FacesContext ctx = FacesContext.getCurrentInstance(); if (ctx.isValidationFailed() || !loadDataAttempt()) { ctx.getApplication().getNavigationHandler() .handleNavigation(ctx, null , &quot;invalid&quot; ); } } Force navigation if preconditions not met
  87. 87. Report downloads 16-11-09 <view xmlns = &quot;http://java.sun.com/jsf/core&quot; > <event type = &quot;preRenderView&quot; listener = &quot;#{reportBean.download}&quot; /> </view>
  88. 88. Pushing the file 16-11-09 public void download() { FacesContext ctx = FacesContext.getCurrentInstance(); pushFile( ctx.getExternalContext(), &quot;/path/to/a/pdf/file.pdf&quot; , &quot;file.pdf&quot; ); ctx.responseComplete() ; }
  89. 89. View actions 16-11-09 <f:view> <f:metadata> ... <f:viewAction execute=&quot;#{catalogBean.onRender}&quot;/> </f:metadata> ... </f:view> Wouldn’t it be nice if we had...? JSF 2.next Including option to disable on postback
  90. 90. View actions 16-11-09 <navigation-rule> <from-view-id> /catalog.xhtml </from-view-id> <navigation-case> <from-action> #{catalogBean.onRender} </from-action> <from-outcome> failure </from-outcome> <to-view-id> /search.xhtml </to-view-id> </navigation-case> </navigation-rule> ...followed by buit-in navigation? JSF 2.next
  91. 91. 16-11-09 View actions vs PreRenderView <ul><li>It’s about timing </li></ul><ul><li>PreRenderView </li></ul><ul><li>Executes before rendering component tree </li></ul><ul><li>View action </li></ul><ul><li>Executes before building component tree </li></ul><ul><li>Why build it just to throw it away? </li></ul>
  92. 92. How do we process this URL? 16-11-09 http://acme.org/catalog/category/electronics
  93. 93. Pretty URLs 16-11-09 <rewrite-rule> <rewrite-view-id> /catalog.xhtml </rewrite-view-id> <rewrite-case> <url-pattern> /catalog </url-pattern> <url-pattern> /catalog/category/ {cat} </url-pattern> <url-pattern> /catalog/category/ {cat} / {page} </url-pattern> </rewrite-case> </rewrite-rule> JSF 2.next View parameter mappings
  94. 94. Producing 16-11-09
  95. 95. 16-11-09 UIOutputLink <ul><li>Basic hyperlink-generating component </li></ul><ul><li>Not aware of: </li></ul><ul><li>context path, </li></ul><ul><li>view ID extension -> servlet mapping, or </li></ul><ul><li>navigation rules </li></ul><ul><li>Manual query string creation </li></ul><ul><li>Does at least support <f:param> </li></ul><h:outputLink value=&quot;/home.jsf&quot;>Home</h:outputLink>
  96. 96. 16-11-09 UIOutcomeTarget <ul><li>Intelligent hyperlink-generating component </li></ul><ul><li>Aware of: </li></ul><ul><li>context path, </li></ul><ul><li>uses navigation handler to derive view ID, and </li></ul><ul><li>can encode view parameters into query string </li></ul><ul><li>Parameter overrides </li></ul><ul><li>Can use <f:param> to set parameter explicitly </li></ul><h:link outcome=&quot;home&quot; value=&quot;Home&quot;/>
  97. 97. Generating bookmarkable links 16-11-09 <h:link value = &quot;Previous&quot; includeViewParams = &quot;true&quot; > <f:param name = &quot;page&quot; value = &quot;#{catalogBean.previousPage}&quot; /> </h:link> <f:metadata> <f:viewParam name = &quot;q&quot; value = &quot;#{catalogBean.query}&quot; /> <f:viewParam name = &quot;page&quot; value = &quot;#{catalogBean.page}&quot; /> </f:metadata> http://acme.org/catalog.jsf? q=portable+hole & page=3 /catalog.xhtml
  98. 98. 16-11-09 GET support: JSF 2.next <ul><li>View actions – <f:viewAction> </li></ul><ul><li>View restrictions – <f:restrictView> </li></ul><ul><li>Consuming pretty URLs – <rewrite-rules> </li></ul><ul><li>Other ideas? </li></ul>
  99. 99. 16-11-09 Navigation Implicit, conditional and preemptive navigation, queryable navigation rules and redirect parameters
  100. 100. 16-11-09 Implicit navigation <ul><li>Fall-through case catering to prototypes </li></ul><ul><li>Logical outcome => view ID </li></ul><ul><li>Applies to: </li></ul><ul><li>return value of action method, </li></ul><ul><li>action of UICommand ( <h:commandButton> ), </li></ul><ul><li>outcome of UIOutcomeTarget ( <h:link> ), or </li></ul><ul><li>NavigationHandler.handleNavigation() method </li></ul>
  101. 101. 16-11-09 Tweaking implicit navigation <ul><li>Can include query string </li></ul><ul><li>/product.xhtml ?id=3 </li></ul><ul><li>Built-in directive to force a redirect </li></ul><ul><li>/product.xhtml ?faces-redirect=true &id=3 </li></ul>
  102. 102. A navigation shorthand 16-11-09 <h:commandButton action = &quot;#{productBean.save}&quot; value = &quot;Save&quot; /> public String save() { // perform save logic, then... return &quot;/catalog.xhtml&quot; ; }
  103. 103. A navigation short (er) hand 16-11-09 Can link to navigation case later <h:commandButton action = &quot;#{productBean.save}&quot; value = &quot;Save&quot; /> public String save() { // perform save logic, then... return &quot; catalog &quot; ; } Relative to current path and view ID
  104. 104. 16-11-09 Logical outcomes aren’t logical <ul><li>Leak into business logic </li></ul><ul><li>Reuse is difficult </li></ul><ul><li>Void methods don’t work </li></ul>
  105. 105. 16-11-09 Conditional navigation <ul><li>Navigation case matched based on state </li></ul><ul><li>Promotes loose coupling </li></ul><ul><li>Action methods don’t return “logical outcome” </li></ul><ul><li>Can reduce number of navigation cases </li></ul><ul><li>Navigation cases not skipped on void outcome </li></ul>Web tier Transactional tier
  106. 106. A conditional case 16-11-09 <navigation-case> <from-action> #{registration.register} </from-action> <if>#{currentUser.registered}</if> <to-view-id> /account.xhtml </to-view-id> <redirect include-view-params = &quot;true&quot; /> </navigation-case>
  107. 107. Matching a void outcome 16-11-09 <navigation-case> <from-action> #{catalog.search} </from-action> <if>#{true}</if> <to-view-id> /results.xhtml </to-view-id> </navigation-case>
  108. 108. 16-11-09 Preemptive navigation <ul><li>Evaluated at render time </li></ul><ul><li>Outcome translated into bookmarkable URL </li></ul><ul><li>Key elements: </li></ul><ul><li>UIOutcomeTarget ( <h:link> , <h:button> ) </li></ul><ul><li>implicit navigation </li></ul><ul><li>view parameters </li></ul>
  109. 109. Bookmarkable link 16-11-09 <h:link outcome = &quot;product&quot; value = &quot;View&quot; > <f:param name = &quot;id&quot; value = &quot;#{product.id}&quot; /> </h:link> <a href=&quot;/product.jsf?id=3&quot;>View</a>
  110. 110. 16-11-09 Redirect parameters <ul><li>No support in JSF 1.x </li></ul><ul><li>Made redirect after POST difficult </li></ul><ul><li>Limited usefulness of declarative navigation </li></ul><ul><li>Two solutions in JSF 2 </li></ul><ul><li>Explicit redirect parameters </li></ul><ul><li>View parameters </li></ul>
  111. 111. Redirect after POST the hard way 16-11-09 FacesContext ctx = FacesContext.getCurrentInstance(); ExternalContext extCtx = ctx.getExternalContext(); String url = ctx.getApplication().getViewHandler() .getActionURL(ctx, &quot;/product.xhtml&quot; ) + &quot;?id=&quot; + getProductId(); try { extCtx.redirect(extCtx.encodeActionURL(url)); } catch (IOException ioe) { throw new FacesException(ioe); }
  112. 112. Redirect after POST the easier way 16-11-09 <navigation-case> <from-action> #{productBean.save} </from-action> <if> #{productBean.id != null} </if> <to-view-id> /product.xhtml </to-view-id> <redirect> <view-param> <name> id </name> <value> #{productBean.id} </value> </view-param> </redirect> </navigation-case>
  113. 113. Redirect after POST the best way 16-11-09 <navigation-case> <from-action> #{productBean.save} </from-action> <if> #{productBean.id != null} </if> <to-view-id> /product.xhtml </to-view-id> <redirect include-view-params = &quot;true&quot; /> </navigation-case>
  114. 114. 16-11-09 Navigation: JSF 2.next <ul><li>Include view parameters automatically </li></ul><ul><li><if>#{true}</if> is ugly </li></ul><ul><li>Navigation rules are XML hell </li></ul><ul><li>A more conscise DSL? </li></ul><ul><li>Java-based configuration? </li></ul><ul><li>Other ideas? </li></ul>
  115. 115. 16-11-09 Resource handling Native resource handling, packaging and resource relocation
  116. 116. 16-11-09 No more “bonus” servlet!
  117. 117. 16-11-09 Resource handling <ul><li>Load resources out of web root or JAR </li></ul><ul><li>Associate resources with UIComponent </li></ul><ul><li>Resources loaded if component is rendered </li></ul><ul><li>Resource loading API </li></ul><ul><li>Localization </li></ul>
  118. 118. Declarative component resources 16-11-09 @ResourceDependency ( name = &quot;jsf.js&quot; , library = &quot;javax.faces&quot; , target = &quot;head&quot; ) public class MyComponent extends UIOutput { ... }
  119. 119. 16-11-09 A resource at a glance <ul><li>Structure </li></ul><ul><li>Name </li></ul><ul><li>Library </li></ul><ul><li>Locale </li></ul><ul><li>Version </li></ul><ul><li>Packaging </li></ul><ul><li>Web root </li></ul><ul><li>/resources </li></ul><ul><li>Classpath </li></ul><ul><li>META-INF/resources </li></ul>
  120. 120. 16-11-09 A third request processing scenario
  121. 121. 16-11-09 Resolving a resource <ul><li>Served from web root </li></ul><ul><li><h:graphicImage name = &quot;visa.png&quot; /> </li></ul><ul><li>Served from classpath of creditcards.jar </li></ul><ul><li><h:graphicImage name = &quot;visa.png&quot; library = &quot;creditcards&quot; /> </li></ul><ul><li><h:graphicImage value = &quot;#{resources['creditcards:visa.png']}&quot; /> </li></ul>localePrefix/libraryName/libraryVersion/ resourceName /resourceVersion Path segments in grey are optional
  122. 122. 16-11-09 Resource relocation <ul><li>Resources can target section of document </li></ul><ul><li>Essential for templating </li></ul><ul><li><html> </li></ul><ul><li><h:head> </li></ul><ul><li><title> Resource Relocation Example </title> </li></ul><ul><li></h:head> </li></ul><ul><li><h:body> </li></ul><ul><li><h:outputScript name = &quot;script.js&quot; target=&quot;head&quot; /> </li></ul><ul><li></h:body> </li></ul><ul><li></html> </li></ul>
  123. 123. 16-11-09 Resources: JSF 2.next <ul><li>Sprite generation </li></ul><ul><li>Compression support </li></ul><ul><li>What else? </li></ul>
  124. 124. 16-11-09 Model Java EE 6 component model, Bean Validation, error handling and resource loading
  125. 125. 16-11-09 Java EE 6: Goals <ul><li>Extensibility </li></ul><ul><li>Allow more components to be standalone (EJB 3.1) </li></ul><ul><li>Profiles </li></ul><ul><li>Subsets of “full” EE platform </li></ul><ul><li>Web Profile </li></ul><ul><li>Pruning </li></ul><ul><li>CMP, JAX-RPC, JAXR, JSR-88 are “pruned” in EE6 </li></ul><ul><li>Technology Improvements </li></ul>
  126. 126. 16-11-09 Java EE 6: Newcomers <ul><li>Managed Beans (part of JSR-316 ) </li></ul><ul><li>Contexts and Dependency Injection - JSR-299 </li></ul><ul><li>Bean Validation - JSR-303 </li></ul><ul><li>JAX-RS (RESTful Web Services) - JSR-311 </li></ul>
  127. 127. 16-11-09 Java EE 6: Notable updates <ul><li>Servlet 3.0 </li></ul><ul><li>JPA 2.0 </li></ul><ul><li>Type-safe Criteria API </li></ul><ul><li>Extra mappings EJB 3.1 </li></ul><ul><li>No-interface views </li></ul><ul><li>Package in wars </li></ul><ul><li>Async and timer support </li></ul><ul><li>Embeddable </li></ul><ul><li>Embeddable </li></ul>...and JSF 2.0, of course!
  128. 128. 16-11-09 Web profile contents <ul><li>Persistence </li></ul><ul><li>JPA 2.0 </li></ul><ul><li>JTA </li></ul><ul><li>Component model </li></ul><ul><li>EJB 3.1 Lite </li></ul><ul><li>Bean Validation </li></ul><ul><li>CDI (JSR-299) </li></ul><ul><li>Presentation </li></ul><ul><li>JSF 2.0 </li></ul><ul><li>Servlet 3.0 </li></ul>
  129. 129. 16-11-09 JSR-299: Essential ingredients <ul><li>Beans types </li></ul><ul><li>Qualifier annotations </li></ul><ul><li>Scope </li></ul><ul><li>Alternatives </li></ul><ul><li>An EL name (optional) </li></ul><ul><li>Interceptors and decorators </li></ul><ul><li>The implementation </li></ul>
  130. 130. Simple example 16-11-09 public class Hello { public String sayHello(String name) { return &quot;Hello, &quot; + name; } } @Stateless public class Hello { public String sayHello(String name) { return &quot;Hello, &quot; + name; } } Any Managed Bean can use CDI services ...even EJBs!
  131. 131. Simple example 16-11-09 public class Printer { @Inject Hello hello ; public void printHello() { System.out.println( hello .sayHello( &quot;Devoxx&quot; )); } } @Inject defines injection point, assumes @Default qualifier
  132. 132. Constructor injection 16-11-09 public class Printer { private Hello hello ; @Inject public Printer(Hello hello) { this . hello = hello; } public void printHello() { System. out .println( hello .sayHello( &quot;Devoxx&quot; )); } } @Inject marks constructor to be called by container; arguments injected automatically
  133. 133. Bean EL names 16-11-09 @Named( &quot;hello&quot; ) public class Hello { private String name; // getters and setters not shown public void sayHello() { System. out .println( &quot;Hello, &quot; + name); } } @Named public class Hello { ... } @Named makes bean available to EL Name can be defaulted to simple name of class
  134. 134. JSF view 16-11-09 <h:inputText value = &quot;#{hello.name}&quot; /> <h:commandButton value = &quot;Say Hello&quot; action = &quot;#{hello.sayHello}&quot; /> Invoking a bean via EL
  135. 135. 16-11-09 Qualifier An annotation that lets a client choose between multiple implementations of an API at runtime
  136. 136. Write a qualified implementation 16-11-09 @Casual public class Hi extends Hello { public String sayHello(String name) { return &quot;Hi, &quot; + name; } } This second Hello bean is qualified @Casual
  137. 137. Using a qualifier 16-11-09 public class Printer { @Inject @Casual Hello hello ; public void printHello() { System. out .println( hello .sayHello( &quot;Devoxx&quot; )); } } Injects the @Casual implementation of Hello
  138. 138. 16-11-09 Scopes and contexts <ul><li>Built-in scopes: </li></ul><ul><li>Any servlet request: @ApplicationScoped , @RequestScoped , @SessionScoped </li></ul><ul><li>JSF requests - @ConversationScoped </li></ul><ul><li>Dependent scope (Default): @Dependent </li></ul><ul><li>Custom scopes </li></ul><ul><li>Define scope type annotation (e.g., @FlashScoped ) </li></ul><ul><li>Context impl defines where bean is stored </li></ul>
  139. 139. 16-11-09 Producer methods <ul><li>Producer methods allow control over bean creation where: </li></ul><ul><li>the objects to be injected are not managed instances </li></ul><ul><li>the concrete type of the objects to be injected may vary at runtime </li></ul><ul><li>the objects require some custom initialization that is not performed by the bean constructor </li></ul>
  140. 140. 16-11-09 Parameterized EL methods <ul><li>Syntax similar to Java method calls </li></ul><ul><li>Method arguments are EL expressions </li></ul><ul><li>Arguments resolved at different times: </li></ul><ul><li>Value expression: at render time </li></ul><ul><li>Method expression: when event is fired </li></ul><ul><li><h:commandButton action = &quot; #{hello.sayHello('Devoxx')} &quot; ... /> <h:commandButton action = &quot; #{hello.sayHello(currentConference)} &quot; .../> </li></ul>
  141. 141. 16-11-09 Validation Bean Validation integration, validating empty fields and multi-field validation with post-validate events
  142. 142. 16-11-09 One model... ...validated across multiple layers Constraints in the enterprise User String username String email
  143. 143. 16-11-09 Bean Validation (JSR-303) <ul><li>Constrain once, validate anywhere </li></ul><ul><li>Centrally define constraints in model class </li></ul><ul><li>Constraints described using annotations </li></ul><ul><li>JSF integration </li></ul><ul><li>Enforce constraints in presentation layer </li></ul><ul><li>Replaces existing JSF validators </li></ul><ul><li>Zero configuration! </li></ul>
  144. 144. Defining constraints on the model 16-11-09 public class User { ... @NotNull @Size(min = 3, max = 25) public String getUsername() { return username ; } @NotNull @Email public String getEmail() { return email ; } }
  145. 145. 16-11-09 One model... ...validated across multiple layers Constraints in JSF User String username String email
  146. 146. Enforcing constraints in the UI 16-11-09 <h:inputText id = &quot;username&quot; value = &quot;#{user.username}&quot; /> <h:inputText id = &quot;email&quot; value = &quot;#{user.email}&quot; /> Zeroconf!
  147. 147. Constraining partially 16-11-09 <h:inputText id = &quot;username&quot; value = &quot;#{user.username}&quot; > <f:validateBean disabled = &quot;true&quot; /> </h:inputText> <f:validateBean validationGroups = &quot;com.acme.BareMinimum&quot; > <h:inputText id = &quot;email&quot; value = &quot;#{user.email}&quot; /> </:validateBean>
  148. 148. 16-11-09 The case of the empty field <ul><li>Validation skipped if value is: </li></ul><ul><li>null </li></ul><ul><li>a zero-length string </li></ul><ul><li>Unless... </li></ul><ul><li>Bean Validation is present or </li></ul><ul><li><context-param> <param-name> javax.faces.VALIDATE_EMPTY_FIELDS </param-name> <param-value> true </param-value> </context-param> </li></ul>
  149. 149. 16-11-09 Do you mean null? <ul><li>Problem : user can’t enter null in text field </li></ul><ul><li>Side-effect : inadvertent database updates </li></ul><ul><li>Solution : interpret empty strings as null </li></ul><context-param> <param-name> javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL </param-name> <param-value> true </param-value> </context-param>
  150. 150. 16-11-09 Multi-field validation <ul><li>A tougher problem than it seems </li></ul><ul><li>Two approaches: </li></ul><ul><li>Compare UIInput values </li></ul><ul><li>PostValidateEvent </li></ul>Before model update After model update <ul><li>Validate populated model </li></ul><ul><li>Bean Validation </li></ul>
  151. 151. Listening for post validate 16-11-09 <h:form> <f:event type=&quot;postValidate&quot; listener=&quot;#{minMax.validate}&quot;/> <h:inputText id = &quot;min&quot; value = &quot;#{bean.min}&quot; binding = &quot;#{minMax.minInput}&quot; /> <h:inputText id = &quot;max&quot; value = &quot;#{bean.max}&quot; binding = &quot;#{minMax.maxInput}&quot; /> <h:commandButton value = &quot;Submit&quot; /> </h:form>
  152. 152. Validating across fields 16-11-09 @Inject FacesContext ctx ; private UIInput minInput , maxInput ; // accessors hidden public void validate () { if ( ctx .isValidationFailed()) { return ; } if ((Integer) maxInput .getValue() < (Integer) minInput .getValue()) { ctx.addMessage( maxInput .getClientId(ctx), new FacesMessage( &quot;cannot be less than min value&quot; )); ctx.validationFailed() ; ctx.renderResponse(); } }
  153. 153. 16-11-09 Validation JSF.next <ul><li>What about postModelUpdate? </li></ul><ul><li>Adding FacesMessages is tedious </li></ul><ul><li>Graph Validation (Bean Validation on object) </li></ul>
  154. 154. 16-11-09 Error handling Exception handlers, exception events, servlet errors and the default error page
  155. 155. 16-11-09 The good news No more swallowed exceptions!
  156. 156. 16-11-09 The bad news You’re still going to get exceptions
  157. 157. 16-11-09 Exception handler <ul><li>Hub for handling unexpected exceptions </li></ul><ul><li>When exception is thrown: </li></ul><ul><li>ExceptionQueuedEvent is published </li></ul><ul><li>Exception handler queues exception </li></ul><ul><li>After each phase: </li></ul><ul><li>Exception handler unwraps first exception, rethrows as FacesException </li></ul>Ugh!
  158. 158. 16-11-09 Default error page
  159. 159. 16-11-09 Development diagnostics <ul><li>Activated when ProjectStage = Development </li></ul><ul><li>Report includes: </li></ul><ul><li>stack trace of exception </li></ul><ul><li>UI component tree </li></ul><ul><li>scoped variables </li></ul><ul><li>view ID and line number </li></ul><ul><li>anything else? </li></ul>/javax.faces.error.xhtml
  160. 160. <ul><li>Exceptions servlet error handler ( web.xml ) </li></ul><ul><li>Several problems: </li></ul><ul><li>Error page is outside of JSF life cycle </li></ul><ul><li>Error page must include servlet mapping </li></ul><ul><li>Context of request is left behind </li></ul>16-11-09 Bubbling over in production <error-page> <exception-type> com.acme.SecurityException </exception-type> <location> /accessDenied.jsf </location> </error-page>
  161. 161. Declarative error handling in JSF 16-11-09 <exception class = &quot;javax.persistence.EntityNotFoundException&quot; > <redirect view-id = &quot;/error/404.xhtml&quot; > <message severity = &quot;warn&quot; > Record not found </message> </redirect> </exception> Wouldn’t it be nice if we had...? JSF 2.next
  162. 162. 16-11-09 Ajax error handling <ul><li>JavaScript error callback for single request </li></ul><ul><li><f:ajax ... onerror = &quot;handle_specific_error&quot; /> </li></ul><ul><li>Global JavaScript error listener </li></ul><ul><li>jsf.ajax.addOnError( handle_all_errors ); </li></ul><ul><li>Alert window fallback in development </li></ul>
  163. 163. 16-11-09 Pain relief Select items from collections, validation failed flag, API improvements, varStatus on ui:repeat, and more...
  164. 164. From collection to select items 16-11-09 <h:selectOneMenu value = &quot;#{product.category}&quot; > <f:selectItems value = &quot; #{catalogBean.categories} &quot; var = &quot;cat&quot; itemLabel = &quot;#{cat.name}&quot; itemValue = &quot;#{cat}&quot; noSelectionValue = &quot;#{catalogBean.defaultCatalog}&quot; /> </h:selectOneMenu> @Named public class CatalogBean { public List<Category> getCategories() { return ...; } }
  165. 165. 16-11-09 Minor improvements that add up <ul><li>Retrieve faces messages as java.util.List </li></ul><ul><li>FacesContext.getMessageList() </li></ul><ul><li>FacesContext.getMessageList(String clientId) </li></ul><ul><li>Preserve faces messages across redirect </li></ul><ul><li>ExternalContext.getFlash().setKeepMessages(true) </li></ul><ul><li>Flag indicating whether validation failed </li></ul><ul><li>FacesContext.isValidationFailed() </li></ul><ul><li>ActionEvent optional for action listeners </li></ul>
  166. 166. 16-11-09 Pain relief: JSF 2.next <ul><li>UIData components </li></ul><ul><li>java.util.Collection </li></ul><ul><li>varStatus </li></ul><ul><li>row state </li></ul><ul><li>Standard components </li></ul><ul><li>h:fileUpload </li></ul><ul><li>Separate spec? </li></ul><ul><li>Facelets from JAR </li></ul><ul><li>EL </li></ul><ul><li>Static methods </li></ul><ul><li>Enum support </li></ul><ul><li>Rendered attribute </li></ul><ul><li>Generated ids </li></ul><ul><li>Container injection </li></ul>
  167. 167. 16-11-09 Community JSR-314-OPEN mailinglist, javaserverfaces-spec-public project, JCP.org and you !
  168. 168. 16-11-09 Steps towards openness <ul><li>Semi- public mailinglist – JSR-314-OPEN </li></ul><ul><li>http://archives.java.sun.com/jsr-314-open.html </li></ul><ul><li>Free registration required to view </li></ul><ul><li>Must be EG member to post </li></ul><ul><li>Public issue tracker – java.net project </li></ul><ul><li>https://javaserverfaces-spec-public.dev.java.net </li></ul><ul><li>No registration required to view </li></ul><ul><li>Free java.net account required to edit </li></ul>
  169. 169. 16-11-09 Next steps <ul><li>Anonymous read access to JSR-314-OPEN </li></ul><ul><li>Allow community to follow along </li></ul><ul><li>Make sharing links easier </li></ul><ul><li>Indexable by search engines </li></ul><ul><li>Non-EG member invites to JSR-314-OPEN </li></ul><ul><li>Prime candidates – implementation team members </li></ul><ul><li>Read-write community mailinglist </li></ul>
  170. 170. 16-11-09 Creating a JCP.org profile Did you know that anyone can have a JCP.org profile? Just sign up!
  171. 171. 16-11-09 JCP.org 2.0 - Launched June 2009 <ul><li>Goals are to enhance: </li></ul><ul><li>participation, </li></ul><ul><li>communication, and </li></ul><ul><li>transparency </li></ul><ul><li>Personalized content </li></ul><ul><li>Discussion boards </li></ul><ul><li>Wiki </li></ul>
  172. 172. 16-11-09 Becoming a JCP member Did you know that anyone can become a JCP member? Just sign the JSPA!
  173. 173. 16-11-09 JCP membership fee (JSPA) <ul><li>Commercial organizations: $5000 </li></ul><ul><li>Educational/non-profit organizations: $2000 </li></ul><ul><li>Java User Groups (JUGs): free ! </li></ul><ul><li>Individuals: free ! </li></ul>
  174. 174. 16-11-09 Membership benefits <ul><li>Submit JSRs </li></ul><ul><li>Serve on a JSR Expert Group (EG) </li></ul><ul><li>Vote in EC elections (reps who vote on specs) </li></ul><ul><li>http://jcp.org/en/participation/committee </li></ul><ul><li>View EC meeting minutes </li></ul>
  175. 175. 16-11-09 JSF community home page <ul><li>Single entry point into the JSF ecosystem: </li></ul><ul><li>Specification and API docs </li></ul><ul><li>Mailinglists and forums </li></ul><ul><li>Issue tracker </li></ul><ul><li>FAQs and guides </li></ul><ul><li>Implementations, component libraries </li></ul>http://javaserverfaces.org (future)
  176. 176. 16-11-09 Summary <ul><li>JSF 2 is a drastic improvement </li></ul><ul><li>Embraced de-facto community standards </li></ul><ul><li>JSR-314 seeks to be role model for openness </li></ul><ul><li>Still lots of room for innovation in JSF 2.next </li></ul><ul><li>You can be part of the process! </li></ul>
  177. 177. 16-11-09 See you at the JSF 2 BOF! (20:00) <ul><li>Learn </li></ul><ul><li>http://tinyurl.com/ jsf2new </li></ul><ul><li>http://tinyurl.com/ jsf2devworks </li></ul><ul><li>http://tinyurl.com/ jsf2dzone </li></ul><ul><li>http://tinyurl.com/ jsf2driscoll </li></ul><ul><li>http://tinyurl.com/ jsf2ryan </li></ul><ul><li>Try </li></ul><ul><li>http://tinyurl.com/ jsf2ri </li></ul><ul><li>http://tinyurl.com/ jsf2issue </li></ul>

×