<Insert Picture Here>Hyperproductive JSF 2.0Arun Gupta, Java EE & GlassFish Guyblogs.sun.com/arungupta, @arungupta
Beijing 2010December 13–16, 2010                       2
The following is intended to outline our generalproduct direction. It is intended for informationpurposes only, and may no...
Features, features, features, ...                                    4
Facelets           5
Facelets• Designed for JSF from beginning• XHTML + CSS  – Document validation• Better error handling, including line numbe...
Facelets – Sample Code<html xmlns="http://www.w3.org/1999/xhtml"  xmlns:ui="http://java.sun.com/jsf/facelets"  xmlns:h="ht...
Composite Components                       8
This...          9
Becomes this...                  10
Or maybe this:                 11
Composite Components• Enable True Abstraction   – Create a true, reusable, component from an     arbitrary region of a pag...
Composite Components – Sample Code                                13
Composite Component – Sample Code<html xmlns="http://www.w3.org/1999/xhtml"  xmlns:ui="http://java.sun.com/jsf/facelets"  ...
Composite Components - Mapping<html xmlns="http://www.w3.org/1999/xhtml"  xmlns:ui="http://java.sun.com/jsf/facelets"  xml...
Integrated Ajax                  16
Integrated Ajax• Inspiration – ADF, RichFaces, IceFaces,  DynamicFaces• Two entry points: – Declarative: <f:ajax> tag, use...
Integrated Ajax – Sample Code<h:commandButton      actionListener="#{sakilabean.findActors}"      value="submit">      <f:...
Partial State Saving                       19
Partial State Saving• Inspired by Trinidad state saving• Save only the state thats changed since creation  of the componen...
View Parameters                  21
View Parameters• Inspired by Page Parameters from Seam• Provides a declarative way to map request parameters to EL-reachab...
System Events                23
System Events• Inspired by Solaris Dtrace, Linux strace, etc.• Publish/Subscribe event bus for things that  happen during ...
System Event Types                     25
System Events – Sample Code<h:inputText>    <f:event type="preValidate"        listener="#{bean.doSomePreValidation}"/></h...
Resources            27
Resources• Standard way to serve image, JavaScripts, CSS, … – No need for separate Servlet or Filter – Logically related t...
Resource EL – Sample Code• #{resource[<resource>]}• #{resource[<library>:<resource>]}• Examples of use  – <a href="#{resou...
Behaviors            30
Behaviors• A Behavior is an interface and invents a new  type of “attached object” which takes part in  decode/encode of a...
Optional “faces-config.xml”• <managed-bean> → @ManagedBean or @Named  – Validator, Renderer, Listener, ...• Default naviga...
Lot more features ...• Annotations• Navigation• Exceptions• Validation• EL• Scopes• Project Stage                        33
Annotations• @ManagedBean• @*Scoped (Session, Request, etc)• @ManagedProperty• @FacesComponent• @FacesConverter• etc.• Wit...
Bookmarkable URLs<h:link outcome="viewEntry" value="Link">  <f:param name="entry" value="#{aBean.entry}"/></h:link><ahref=...
EL (Expression Langauge)• #{component}, #{cc} (composite  component): get the “currently” processed  component / composite...
Validation• Integration with JSR 303: Bean Validation   – @NotEmpty String name;   – default validator: javax.faces.Bean –...
Project Stage• Inspired by Rails• Development   – Better error reporting, debugging• Production  – Better performance     ...
References• glassfish.org• blogs.sun.com/theaquarium• youtube.com/user/GlassFishVideos• facebook.com/glassfish• Follow @gl...
<Insert Picture Here>Hyperproductive JSF 2.0Arun Gupta, Java EE & GlassFish Guyblogs.sun.com/arungupta, @arungupta
Upcoming SlideShare
Loading in …5
×

Hyperproductive JSF 2.0 @ JavaOne Brazil 2010

2,706 views
2,659 views

Published on

Hyperproductive JSF 2.0 @ JavaOne Brazil 2010

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,706
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
122
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Hyperproductive JSF 2.0 @ JavaOne Brazil 2010

  1. 1. <Insert Picture Here>Hyperproductive JSF 2.0Arun Gupta, Java EE & GlassFish Guyblogs.sun.com/arungupta, @arungupta
  2. 2. Beijing 2010December 13–16, 2010 2
  3. 3. The following is intended to outline our generalproduct direction. It is intended for informationpurposes only, and may not be incorporated into anycontract. It is not a commitment to deliver anymaterial, code, or functionality, and should not berelied upon in making purchasing decisions.The development, release, and timing of anyfeatures or functionality described for Oracle’sproducts remains at the sole discretion of Oracle. 3
  4. 4. Features, features, features, ... 4
  5. 5. Facelets 5
  6. 6. Facelets• Designed for JSF from beginning• XHTML + CSS – Document validation• Better error handling, including line numbers• Library prefixes as namespaces• EL directly in page: – #{bean.propertyname}• Templating made easy – ui:composition, ui:define, ui:insert – ui:include, ui:repeat 6
  7. 7. Facelets – Sample Code<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"> <h:head> <title>Enter Name &amp; Password</title> </h:head> <h:body> <h1>Enter Name &amp; Password</h1> <h:form> <h:panelGrid columns="2"> <h:outputText value="Name:"/> <h:inputText value="#{simplebean.name}" title="name" id="name" required="true"/> <h:outputText value="Password:"/> <h:inputText value="#{simplebean.password}" title="password" id="password" required="true"/> </h:panelGrid> <h:commandButton action="show" value="submit"/> </h:form> </h:body></html> 7
  8. 8. Composite Components 8
  9. 9. This... 9
  10. 10. Becomes this... 10
  11. 11. Or maybe this: 11
  12. 12. Composite Components• Enable True Abstraction – Create a true, reusable, component from an arbitrary region of a page – Built by composing other components• “Using” and “Defining” page• Full support for using attached objects in the using page – Action methods – Validators, etc 12
  13. 13. Composite Components – Sample Code 13
  14. 14. Composite Component – Sample Code<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"> <h:head> <title>Enter Name &amp; Password</title> </h:head> <h:body> <h1>Enter Name &amp; Password</h1> <h:form> <h:panelGrid columns="2"> <h:outputText value="Name:"/> <h:inputText value="#{simplebean.name}" title="name" id="name" required="true"/> <h:outputText value="Password:"/> <h:inputText value="#{simplebean.password}" title="password" id="password" required="true"/> </h:panelGrid> <h:commandButton action="show" value="submit"/> </h:form> </h:body></html> 14
  15. 15. Composite Components - Mapping<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:ez="http://java.sun.com/jsf/composite/ezcomp"> <h:head> <title>Enter Name &amp; Password</title> </h:head> <h:body> <h1>Enter Name &amp; Password</h1> <h:form> <ez:username-password/> <h:commandButton action="show" value="submit"/> </h:form> </h:body></html> . . . WEB-INF index.xhtml resources/ ezcomp/ username-password.xhtml http://blogs.sun.com/arungupta/entry/totd_147_java_server_faces 15
  16. 16. Integrated Ajax 16
  17. 17. Integrated Ajax• Inspiration – ADF, RichFaces, IceFaces, DynamicFaces• Two entry points: – Declarative: <f:ajax> tag, uses AjaxBehavior – Programmatic ajax • resource library javax.faces • resource name jsf.js • JavaScript namespace jsf.ajax. – jsf.ajax.request function 17
  18. 18. Integrated Ajax – Sample Code<h:commandButton actionListener="#{sakilabean.findActors}" value="submit"> <f:ajax execute="length" render="actorTable totalActors"/></h:commandButton>http://blogs.sun.com/arungupta/entry/totd_123_f_ajax_bean 18
  19. 19. Partial State Saving 19
  20. 20. Partial State Saving• Inspired by Trinidad state saving• Save only the state thats changed since creation of the component tree• Per-view state size up to 4X smaller• Default for pages written with Facelets• All standard components implement this feature – Default for composite components 20
  21. 21. View Parameters 21
  22. 22. View Parameters• Inspired by Page Parameters from Seam• Provides a declarative way to map request parameters to EL-reachable location – <f:viewParam>, <f:metadata><f:metadata> <f:viewParam name="foo" value="#{bean.foo}"/></f:metadata>page1.xhtml?foo=barbean.foo will equal “bar” 22
  23. 23. System Events 23
  24. 24. System Events• Inspired by Solaris Dtrace, Linux strace, etc.• Publish/Subscribe event bus for things that happen during the JSF Lifecycle• Adds to event listening abilities – FacesEvent/FacesListener – PhaseEvent/PhaseListener – SystemEvent/SystemEventListener 24
  25. 25. System Event Types 25
  26. 26. System Events – Sample Code<h:inputText> <f:event type="preValidate" listener="#{bean.doSomePreValidation}"/></h:inputText><h:inputText value="#{myBean.text}"> <f:event type="beforeRender" listener="#{myBean.beforeTextRender}"/></h:inputText> 26
  27. 27. Resources 27
  28. 28. Resources• Standard way to serve image, JavaScripts, CSS, … – No need for separate Servlet or Filter – Logically related to components, treat them that way• @ResourceDependency or @ResourceDependencies on custom components• Built in support for CSS, Image, JavaScript resources• /resources or /META-INF/resources 28
  29. 29. Resource EL – Sample Code• #{resource[<resource>]}• #{resource[<library>:<resource>]}• Examples of use – <a href="#{resource[header.jpg]}" /> – <h:graphicImage value="#{resource[corp:header.jpg]}" /> 29
  30. 30. Behaviors 30
  31. 31. Behaviors• A Behavior is an interface and invents a new type of “attached object” which takes part in decode/encode of a component• 3 new behaviors – ClientBehavior, ClientBehaviorHolder, AjaxBehavior<h:commandLink onclick="return confirm(Really???)"/><h:commandLink> <foo:confirm message="Really???"/></h:commandLink> 31
  32. 32. Optional “faces-config.xml”• <managed-bean> → @ManagedBean or @Named – Validator, Renderer, Listener, ...• Default navigation rules – match a view on the disk – Conditional navigation @Named(“simplebean”) public class SimpleBean { . . . } <h:commandButton action="show" value="submit"/> 32
  33. 33. Lot more features ...• Annotations• Navigation• Exceptions• Validation• EL• Scopes• Project Stage 33
  34. 34. Annotations• @ManagedBean• @*Scoped (Session, Request, etc)• @ManagedProperty• @FacesComponent• @FacesConverter• etc.• With implicit Navigation, may eliminate need for faces-config.xml in many cases 34
  35. 35. Bookmarkable URLs<h:link outcome="viewEntry" value="Link"> <f:param name="entry" value="#{aBean.entry}"/></h:link><ahref="http://localhost:8080/myapp/viewEntry.xhtml?entry=entry1">Link</a> 35
  36. 36. EL (Expression Langauge)• #{component}, #{cc} (composite component): get the “currently” processed component / composite component• #{component.clientId}• #{component.messageList} 36
  37. 37. Validation• Integration with JSR 303: Bean Validation – @NotEmpty String name; – default validator: javax.faces.Bean – automatically applied to all input fields• Default-validator: hook up a validator for all instances of EditableValueHolder• <f:validateBean>, <f:validateRequired>, <f:validateRegexp> 37
  38. 38. Project Stage• Inspired by Rails• Development – Better error reporting, debugging• Production – Better performance 38
  39. 39. References• glassfish.org• blogs.sun.com/theaquarium• youtube.com/user/GlassFishVideos• facebook.com/glassfish• Follow @glassfish 39
  40. 40. <Insert Picture Here>Hyperproductive JSF 2.0Arun Gupta, Java EE & GlassFish Guyblogs.sun.com/arungupta, @arungupta

×