A Complete Tour of JSF 2

39,389 views
39,140 views

Published on

A complete tour of the JSF 2 platform, as presented at Oracle Open World, 2009

Published in: Technology
2 Comments
26 Likes
Statistics
Notes
No Downloads
Views
Total views
39,389
On SlideShare
0
From Embeds
0
Number of Embeds
528
Actions
Shares
0
Downloads
1,643
Comments
2
Likes
26
Embeds 0
No embeds

No notes for slide
  • Heading should be V3 Express? Change the dates and names
  • test
  • Heading should be V3 Express? Change the dates and names
  • A Complete Tour of JSF 2

    1. 1. A Complete Tour of JavaServer Faces 2.0 Jim Driscoll [email_address] Andy Schwartz [email_address]
    2. 2. What's new?
    3. 3. Almost Everything
    4. 4. Faces Expert Group <ul><li>Sun – Ed Burns, Roger Kitain (Spec leads)
    5. 5. Oracle
    6. 6. Apache
    7. 7. IceFaces
    8. 8. RichFaces
    9. 9. RedHat / Seam
    10. 10. Book Authors
    11. 11. Many more </li></ul>
    12. 12. All of the Faces of Faces at Sun R Ed Burns Jim Driscoll Roger Kitain Ryan Lubke
    13. 13. Most of the Faces of the EG Andy Schwartz Dan Allen Alexandr Smirnov Ken Paulsen Martin Marinschek Pete Muir Kito Mann Joe Ottinger Ted Goddard Neil Griffin Jason Lee David Geary Mike Freedman Gavin King R Jeremy Grelle Keith Donald Ed Burns Jim Driscoll Roger Kitain Ryan Lubke
    14. 14. Some Faces of the Faces Community Andy Schwartz Dan Allen Jacob Hookom Alexandr Smirnov Ken Paulsen Martin Marinschek Matthias We ßendorf Pete Muir Alexander Jesse Imre O ßwald Yara Senger Lincoln Baxter III Adam Winer Craig McClanahan Kito Mann Rick Hightower Joe Ottinger Ted Goddard Neil Griffin Jason Lee Stan Silvert David Geary Mike Freedman Gavin King Hazem Saleh Çağatay Çivici Dennis Byrne Roger Keays Amy Fowler Max Katz R Jeremy Grelle Keith Donald
    15. 15. Community Ideas <ul><li>Innovation happens everywhere
    16. 16. Most ideas were proven in the community before adoption
    17. 17. Some approaches (i.e., Ajax) required a good deal of merging
    18. 18. Highlights on each feature </li></ul>
    19. 19. Features, features
    20. 20. Facelets
    21. 21. Facelets <ul><li>Almost exactly the same as existing Facelets technology
    22. 22. JSP still supported, but... </li><ul><li>All new features will be in Facelets
    23. 23. Facelets now the preferred View Declaration Language </li></ul><li>Designed for JSF from the beginning </li></ul>
    24. 24. Facelets <ul><li>XHTML based – document validation
    25. 25. Better error handling, including line numbers
    26. 26. Library prefixes as namespaces
    27. 27. EL directly in page: </li><ul><li>#{bean.propertyname} </li></ul><li>Templating made easy </li><ul><li>ui:composition, ui:define, ui:insert
    28. 28. ui:include, ui:repeat </li></ul></ul>
    29. 29. Composite Components
    30. 30. This...
    31. 31. Becomes this...
    32. 32. Or maybe this:
    33. 33. Composite Components <ul><li>Enable True Abstraction </li><ul><li>Create a true, reusable, component from an arbitrary region of a page
    34. 34. Built by composing other components </li></ul><li>Full support for using attached objects in the using page, and mapping them to arbitrary targets within the composite component </li><ul><li>Action methods
    35. 35. Validators, etc </li></ul></ul>
    36. 36. Composite Components <ul><li>Builds on top of Resources and Facelets
    37. 37. Heavily leverages naming conventions </li><ul><li>Resource dir
    38. 38. Library name is directory name
    39. 39. Tag name is file name </li></ul><li>Essentially special-case templating </li></ul>
    40. 40. Composite Component In file ctx-root/resources/simpleout/out.xhtml: <composite:interface> <composite:attribute name=&quot;value&quot; required=&quot;true&quot;/> </composite:interface> <composite:implementation> <h:outputText value=&quot;#{cc.attrs.value}&quot; style=&quot;background-color: yellow&quot;/> </composite:implementation>
    41. 41. Composite Component <html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xmlns:h=&quot;http://java.sun.com/jsf/html&quot; xmlns:f=&quot;http://java.sun.com/jsf/core&quot; xmlns:ez=&quot;http://java.sun.com/jsf/composite/simpleout&quot;> .... <ez:out value=&quot;Test Value&quot;/> ....
    42. 42. Ajax
    43. 43. Ajax <ul><li>Inspiration: ADF Faces, RichFaces, IceFaces, DynamicFaces
    44. 44. Two entry points: </li><ul><li>Declarative: <f:ajax> tag, uses AjaxBehavior
    45. 45. Programmatic ajax: resource library javax.faces , resource name jsf.js , JavaScript namespace jsf.ajax. </li><ul><li>jsf.ajax.request function </li></ul></ul></ul>
    46. 46. Ajax <ul><li>Declarative ajax: useful to ajaxify non ajax pages </li><ul><li>Add ajax behaviors “invisibly”
    47. 47. Supports many Ajax usecases </li></ul><li>JavaScript Ajax API usage pattern </li><ul><li>jsf.ajax.request() JavaScript function
    48. 48. Integrate with existing Ajax widgets </li></ul><li>Simplify lifecycle view: execute and render </li></ul>
    49. 49. Ajax Tag Example <h:outputText id=&quot;out1&quot; value=&quot;#{count.count}&quot;/> <h:commandButton value=&quot;Count&quot;> <f:ajax render=”out1”/> </h:commandButton>
    50. 50. Partial State Saving
    51. 51. Partial State Saving <ul><li>Inspired by Trinidad state saving
    52. 52. Save only the state that's changed since creation of the component tree
    53. 53. Per-view state size up to 4X smaller than before
    54. 54. Default for pages written with Facelets
    55. 55. Of interest to Java custom component authors
    56. 56. All standard components implement this feature - your composite components will automatically take advantage of it. </li></ul>
    57. 57. Partial State Saving <ul><li>PartialStateHolder behavioral interface, extends existing StateHolder . </li><ul><li>PartialStateHolder.markInitialState() </li></ul><li>StateHelper , from UIComponent , does most of the work: replace ivars with keys within StateHelper </li><ul><li>No longer need custom saveState/restoreState() implementations </li></ul></ul>
    58. 58. Simplify Custom Components public class MyInput extends UIComponentBase { private enum Keys { name } public String getName() { return getStateHelper().get(name); } public void setName(String nameParam) { getStateHelper().put(name, nameParam); } }
    59. 59. View Parameters
    60. 60. View Parameters <ul><li>Inspired by Page Parameters from JBoss Seam
    61. 61. Provides a way to map request parameters to special components within the view
    62. 62. <f:metadata>
    63. 63. <f:viewParam> </li></ul>
    64. 64. View Parameters <f:metadata> <f:viewParam name=&quot;foo&quot; value=&quot;#{bean.foo}&quot;/> </f:metadata> page1.xhtml?foo=bar bean.foo will equal “bar”
    65. 65. View Parameters <ul><li>UIViewParameter extends UIInput
    66. 66. All attached objects valid for UIInput are valid – validation and conversion
    67. 67. Breaks the tyranny of POST
    68. 68. Lays the foundation for Bookmarkable pages </li></ul>
    69. 69. System Events
    70. 70. System Events <ul><li>Influenced by JSFTemplating </li><ul><li>Inspired by Solaris Dtrace, Linux strace, etc. </li></ul><li>Publish/Subscribe event bus for things that happen during the JSF Lifecycle
    71. 71. Adds to event listening abilities: </li><ul><li>FacesEvent/FacesListener
    72. 72. PhaseEvent/PhaseListener
    73. 73. SystemEvent/SystemEventListener </li></ul></ul>
    74. 74. System Event Types
    75. 75. System Events <ul><li>Listeners can be registered at three scopes </li><ul><li>component UIComponent.subscribeToEvent()
    76. 76. view UIViewRoot.subscribeToEvent()
    77. 77. application Application.subscribeToEvent() </li></ul><li>Publish is always Application.publishEvent() </li></ul>
    78. 78. Declarative System Events <h:inputText> <f:event type=&quot;preValidate&quot; listener=&quot;#{bean.doSomePreValidation}&quot;/> </h:inputText>
    79. 79. Resources
    80. 80. Resources <ul><li>Avoid need for separate Filter or Servlet.
    81. 81. Resources are logically related to components, treat them that way.
    82. 82. Load from Classpath, or filesystem
    83. 83. Full support for “Library” concept, I18N, Versioning </li></ul>
    84. 84. Resources Java API <ul><li>@ResourceDependency or @ResourceDependencies annotation on </li><ul><ul><li>UIComponent , Renderer , Validator , Converter , ClientBehavior </li></ul></ul><li>attributes for resource name, library name
    85. 85. attribute for target: head, body, form
    86. 86. Built in support for CSS, Image, JavaScript resources </li></ul>
    87. 87. Resources Markup API <ul><li><h:head> , <h:body> </li><ul><li>Used for resource relocation targets </li></ul><li><h:outputScript> , <h:outputStylesheet> </li><ul><li>Attributes for resource name, library name
    88. 88. Attribute for target: head, body, form
    89. 89. Smart includes, useful for composite components </li></ul></ul>
    90. 90. Resource EL <ul><li>#{resource['<resource>']}
    91. 91. #{resource['<library>:<resource>']}
    92. 92. Examples of use </li><ul><li><a href=&quot;#{resource['header.jpg']}&quot; />
    93. 93. <h:graphicImage value=&quot;#{resource['corp:header.jpg']}&quot; /> </li></ul></ul>
    94. 94. Behaviors
    95. 95. Behaviors <ul><li>A Behavior is an interface and invents a new type of “attached object” which takes part in decode/encode.
    96. 96. ClientBehavior extends Behavior
    97. 97. Define things that happen in the view, in the browser
    98. 98. Currently only one standard ClientBehavior implementation: AjaxBehavior
    99. 99. New interface: ClientBehaviorHolder , implemented by all components in javax.faces.component.html
    100. 100. Special ClientBehaviorRenderer , does not extend Renderer . </li><ul><li>getScript() , decode() </li></ul></ul>
    101. 101. View Traversal
    102. 102. View Traversal <ul><li>1.2: UIComponent.invokeOnComponent() </li><ul><li>Single component in context </li></ul><li>VisitContext.createVisitContext()
    103. 103. UIComponent.visitTree(VisitContext) </li><ul><li>Multiple components in context </li></ul><li>Used on Ajax requests for partial traversal
    104. 104. Used by new StateManagementStrategy </li></ul>
    105. 105. More features <ul><li>Annotations
    106. 106. Navigation
    107. 107. Exceptions
    108. 108. Validation
    109. 109. EL
    110. 110. Scopes
    111. 111. Project Stage </li></ul>
    112. 112. Annotations <ul><li>@ManagedBean
    113. 113. @*Scoped (Session, Request, etc)
    114. 114. @ManagedProperty
    115. 115. @FacesComponent
    116. 116. @FacesConverter
    117. 117. etc.
    118. 118. With implicit Navigation, may eliminate need for faces-config.xml in many cases </li></ul>
    119. 119. Navigation <ul><li>Bookmarkable Pages </li><ul><li>Uses View Parameters to ensure request params are validated before rendering page
    120. 120. New components <h:link> , <h:button> , cause the browser to submit GET request, contrast with <h:command{Button|Link}>
    121. 121. <f:param> add GET params
    122. 122. <h:button outcome=”next” value=”Go” includeViewParams=”true”/> </li><ul><li>Inverse mapping of view params </li></ul></ul></ul>
    123. 123. Navigation <ul><li>Implicit Navigation </li><ul><li>If you don’t want all that <navigation-rules> stuff, you can put the navigation logic straight in the page. </li></ul><li>Conditional Navigation – if statements
    124. 124. ConfigurableNavigationHandler </li><ul><li>Query navigation rules at run-time </li></ul></ul>
    125. 125. Exceptions <ul><li>ExceptionHandler </li><ul><li>can be decorated
    126. 126. all interesting exceptions flow through the exception handler!
    127. 127. new exception type: UpdateModelException </li></ul><li>ValidatorException contains multiple FacesMessages </li></ul>
    128. 128. EL <ul><li>#{component} , #{cc} (composite component) : get the “currently” processed component / composite component
    129. 129. #{component.clientId}
    130. 130. #{component.messageList} </li></ul>
    131. 131. EL <ul><li>Make ActionEvent param optional for action-listeners
    132. 132. For EE6, EL method invocation supports parameters </li><ul><li>makes f:setPropertyActionListener obsolete </li></ul></ul>
    133. 133. Validation <ul><li>Integration with JSR 303: Bean Validation </li><ul><li>@NotEmpty private String name;
    134. 134. default validator: javax.faces.Bean – automatically applied to all input fields </li></ul><li>Default-validator: hook up a validator for all instances of EditableValueHolder
    135. 135. preValidate/postValidate system events </li></ul>
    136. 136. New Validation Tags <ul><li><f:validateBean> </li><ul><li>Beans validation tag </li></ul><li><f:validateRequired> </li><ul><li>Required field </li></ul><li><f:validateRegexp> </li><ul><li>Regular expression validation </li></ul></ul>
    137. 137. New Scopes <ul><li>“ conversation” comes from Java Contexts and Dependency Injection (JSR 299) nee “Weld”
    138. 138. Flash: inspired by Ruby on Rails </li><ul><li>accessible from EL or ExternalContext
    139. 139. useful for storing data for use on the “next” request
    140. 140. preserves FacesContext-messages across redirects </li></ul></ul>
    141. 141. New Scopes <ul><li>View: persists as long as user interacts with the same view </li><ul><li>managed-beans can be put in view-scope </li></ul><li>Custom Scopes </li></ul>
    142. 142. Project Stage <ul><li>Inspired by Rails
    143. 143. Development </li><ul><li>Better error reporting, debugging </li></ul><li>Production </li><ul><li>Better performance </li></ul></ul>
    144. 144. Using JSF 2.0 Now <ul><li>Project Mojarra </li><ul><li>FCS in a few weeks
    145. 145. https://javaserverfaces.dev.java.net/ </li></ul></ul>
    146. 146. Color coded JavaDocs http://javaserverfaces.dev.java.net/docs/2.0/ <ul><li>New in 2.0
    147. 147. Changed in 2.0
    148. 148. Deprecated in 2.0 (JSP) </li></ul>M
    149. 149. Blogs for more detail <ul><li>http://andyschwartz.wordpress.com/2009/07/31/whats-new-in-jsf-2/
    150. 150. http://www.java.net/blogs/driscoll/
    151. 151. http://blogs.sun.com/rlubke/
    152. 152. http://www.java.net/blogs/edburns/
    153. 153. http://www.java.net/blogs/rogerk/ </li></ul>
    154. 154. Further Reading <ul><li>http://javaserverfaces.dev.java.net/docs/2.0
    155. 155. David Geary's writeup: </li><ul><li>http://www.ibm.com/developerworks/java/library/j-jsf2fu1/index.html </li></ul><li>Java EE Tutorial (out soon)
    156. 156. Several additional books will be out this year </li></ul>
    157. 157. A Complete Tour of JavaServer Faces 2.0 Jim Driscoll [email_address] Andy Schwartz [email_address]

    ×