JSF 2.0 (JavaEE Webinar)

5,019 views

Published on

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

No Downloads
Views
Total views
5,019
On SlideShare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
334
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide
  • Open Source from Sun allows a combined vision of the stack - Open Source provides the quality gained from thousands of developers reviewing and testing the quality of the product, the innovations which are determined by the community who builds what they need not what a vendor desires or has been driven by a few major customers, allows customers full transparency into the source code to determine extensions and how to leverage code to full use, and last , open source allows customers to pay at the point of their value of the product – at production time not at the intial stages of development. Closed source solutions are a drain on the enterprise by costing up front extensive license fees plus uncontrolled annual maintenance fees, tools which improve productivity are often complex and they plus extensions built by the vendor lead to planned lock in.
  • Small subset of EJB 3.1 API required by Java EE Platform 6 Web Profile Broadens the availability of EJB technology Without losing portability Any 3.1 Lite application can be deployed to Web Profile and Full Java EE 6 Platform Made possible by simplified .war packaging
  • Open Source from Sun allows a combined vision of the stack - Open Source provides the quality gained from thousands of developers reviewing and testing the quality of the product, the innovations which are determined by the community who builds what they need not what a vendor desires or has been driven by a few major customers, allows customers full transparency into the source code to determine extensions and how to leverage code to full use, and last , open source allows customers to pay at the point of their value of the product – at production time not at the intial stages of development. Closed source solutions are a drain on the enterprise by costing up front extensive license fees plus uncontrolled annual maintenance fees, tools which improve productivity are often complex and they plus extensions built by the vendor lead to planned lock in.
  • JSF 2.0 (JavaEE Webinar)

    1. 1. JavaServer Faces 2.0 Overview Roger Kitain JSF Co-Specification Lead mailto:Roger.Kitain@Sun.Com http://www.java.net/blogs/rogerk/ https://twitter.com/rogerk09
    2. 2. Hi Level Categories of Features Foundational New Features Large New Features
    3. 3. System Events <ul><li>Publish/Subscribe event model
    4. 4. JSF Lifecycle events
    5. 5. Listeners registered at 3 scopes: </li><ul><li>Component: UIComponent.subscribeToEvent()
    6. 6. View: UIViewRoot.subscribeToEvent()
    7. 7. Application: Application.subscribeToEvent() </li></ul><li>Publish using: </li><ul><li>Application.publishEvent() </li></ul><li>Declarative component event listener registration: </li></ul><h:inputText> <f:event type=”preValidate” listener=”#{bean.preVal}”/> </h:inputtext>
    8. 8. Resources <ul><li>No need for separate Filter or Servlet
    9. 9. Loaded from Classpath or filesystem
    10. 10. Library / i18n / Versioning Support
    11. 11. Java API: </li><ul><li>@ResourceDependency ; @ResourceDependencies </li><ul><li>Attributes: library name; resource name
    12. 12. “ Target” Attribute: head, body, form </li></ul></ul><li>Markup: </li><ul><li><h:head> <h:body> <h:outputScript> <h:outputStylesheet> </li></ul></ul>
    13. 13. Resources
    14. 14. View Traversal <ul><li>Multiple components in the view visited for a single traversal
    15. 15. Useful for component(s) processing
    16. 16. VisitContext </li><ul><li>Specifies components to visit
    17. 17. createVisitContext() </li></ul><li>UIComponent.visitTree() </li><ul><li>Performs component(s) visit </li></ul><li>Usages: Ajax ; State Saving </li></ul>
    18. 18. Partial State Saving <ul><li>JSF 1.x State Saving: </li><ul><li>Tedious/error prone for component developers
    19. 19. Performance issues(session bloat) </li></ul><li>JSF 2.0: Partial State Saving </li><ul><li>Only save what's changed since initial view creation
    20. 20. Per view state size up to 4 x smaller
    21. 21. Default for JSF 2.0 components (written with Facelets)
    22. 22. PartialStateHolder </li><ul><li>signals when initial state is configured : markInitialState() </li></ul><li>StateHelper </li><ul><li>Storage map for component state (attributes,listeners,...)
    23. 23. No need for saveState/restoreState </li></ul></ul></ul>
    24. 24. GET Request Support View Parameters <ul><li>Map incoming GET request parameter values to any EL bean/property
    25. 25. Mappings specified with <f:viewParam> component: </li></ul><f:metadata> <f:viewParam name=”user” value=”#{bean.userName}” /> </f:metadata> <ul><li>GET Request: page1.xhtml?user=johndoe
    26. 26. <f:viewParam> is EditableValueHolder </li><ul><li>converters/validators can be used on view parameters </li></ul></ul>
    27. 27. GET Request Support <h:link> <h:button> <ul><li>Issue GET requests without hand coding destination URL
    28. 28. Uses JSF navigation system for determining destination </li></ul><h:link outcome=”success”/> <ul><li>Destination determined at render time </li><ul><li>Outcome mapped to target view identifier </li></ul><li>Integrate with view parameters: </li></ul><h:link outcome=”success” includeViewParams=”true”/> <ul><li>Can use <f:param> to specify parameters too </li></ul>
    29. 29. JSF 2.0 Component Model Why Do We Need It? <ul><li>With the 1.x component model – too many artifacts, hooks: </li><ul><li>Component class
    30. 30. Renderer
    31. 31. Tag class
    32. 32. Tld
    33. 33. faces-config.xml
    34. 34. ...... </li></ul></ul>
    35. 35. JSF 2.0 Component Model <ul><li>Powerful tools: </li><ul><li>Templating </li></ul><li>Facelets is the foundation </li><ul><li>Optimized for JSF
    36. 36. XHTML and tags
    37. 37. Eliminates translation/compilation
    38. 38. Templating
    39. 39. Composite Components </li></ul></ul>
    40. 40. JSF 2.0 Component Model <ul><li>Facelets 2.0 </li><ul><li>Contains most of the standard Facelets features
    41. 41. Enhanced to work with JSF 2.0 component building </li><ul><li>Easily attach listeners, validators, converters
    42. 42. Namespaces created “automagically” – no more taglibs </li></ul><li>Supports Composite Components
    43. 43. It's in the specification ! </li></ul></ul>
    44. 44. Composite Components <ul><li>Turns page markup into a JSF UI component with attached validators, converters, listeners
    45. 45. True abstraction: </li><ul><li>Reuseable component </li></ul></ul>Using Page (XHTML) <html … xlms:my=”http....”> <my:comp value=”yes” /> </html> Component (XHTML)
    46. 46. Composite Components <ul><li>Convention over configuration </li><ul><li>Resources dir; Library name is directory name;
    47. 47. Tag name is file name </li></ul></ul><html xmlns=”http:///www/w3/org/1999/xhtml” xmlns:h=” http://java.sun.com/jsf/html ” xmlns:f=” http://java.sun.com/jsf/core ” xmlns: my =” http://java.sun.com/jsf/composite/comp ”> < my : out value=”yes”/> On disk: <context root>/resources/ comp / out .xhtml
    48. 48. Composite Components What's Inside The Black Box? <ul><li>Interface </li><ul><li>The usage contract
    49. 49. Everything page author needs to know to use component </li></ul><li>Implementation </li><ul><li>Markup used to create component </li></ul></ul>
    50. 50. Composite Components <context-root>resources/ezcomp/LoginPanel.xhtml <html... xmlns:ui=&quot;http://java.sun.com/jsf/facelets&quot; xmlns: cc =&quot;http://java.sun.com/jsf/composite&quot;> ... <cc:interface> <cc:attribute name=”userVal” required=”true” ”/> <cc:attribute name=”passValue” required=”true” /> </cc:interface> <cc:implementation> <div> Username: <h:inputText id=”userId”” value=” #{cc.attrs.userVal }”/> </div> <div>Password: <h:inputSecret id=”passId” value=” #{cc.attrs.passVal} ” /></div> <div> <h:commandButton value=”Login” id=”loginButton” /> </div> </cc:implementation> ....
    51. 51. Composite Components <context-root>resources/ezcomp/LoginPanel.xhtml <html... xmlns:ui=&quot;http://java.sun.com/jsf/facelets&quot; xmlns: cc =&quot;http://java.sun.com/jsf/composite&quot;> ... <cc:interface> <cc:attribute name=”userVal” required=”true” ”/> <cc:attribute name=”passValue” required=”true” /> <cc:actionSource name=&quot;loginAction” targets=”loginButton” /> </cc:interface> <cc:implementation> <div> Username: <h:inputText id=”userId”” value=” #{cc.attrs.userVal }”/> </div> <div>Password: <h:inputSecret id=”passId” value=” #{cc.attrs.passVal} ” /></div> <div> <h:commandButton value=”Login” id=” loginButton ” /> </div> </cc:implementation> ....
    52. 52. Composite Components “Using Page” xmlns:ez=&quot; http://java.sun.com/jsf/composite/ezcomp &quot;> <ul><html...xmlns:ui=&quot; http://java.sun.com/jsf/facelets &quot; </ul>… <h:form> <div id=&quot;compositeComponent&quot; class=&quot;grayBox&quot; style=&quot;border: 1px solid #090;&quot;> <ez:loginPanel > <f:actionListener for=”loginAction” binding=”#{bean.action}” /> </ez:loginPanel> </div> <p><h:commandButton value=&quot;reload&quot; /></p> </h:form>
    53. 53. Enhancing JSF 2.0 Components <ul><li>Other prominent JSF 2.0 additions: </li><ul><li>Ajax
    54. 54. Behaviors </li></ul><li>Work well with composite components </li></ul>
    55. 55. Enhancing JSF 2.0 Components Ajax <ul><li>JavaScript api in the specification </li><ul><li>jsf.ajax.request .....
    56. 56. Useful for making JSF Ajax calls from JavaScript
    57. 57. Control component processing on the server and component rendering at the client </li></ul></ul>
    58. 58. Enhancing JSF 2.0 Components Ajax : Declarative Solution : <f:ajax /> <ul><li>Serves two roles depending on placement: </li><ul><li>Nested within single component </li><ul><li>“ ajaxifies” that component </li></ul><li>Wrapping approach – tag is placed around a group of components </li><ul><li>“ ajaxifies” all components that support the “events” attribute </li></ul></ul></ul>
    59. 59. Enhancing JSF 2.0 Components Ajax : Declarative Solution : <f:ajax /> <h:commandButton ...> <h:commandButton...> <f:ajax event=”action” /> <f:ajax /> </h:commandButton> </h:commandButton> Do exactly the same thing since “action” is the default event for commandButton components. <h:commandButton...> <f:ajax event=”mouseover”/> </h:commandButton> JavaScript events supported too.
    60. 60. Enhancing JSF 2.0 Components Ajax : Declarative Solution : <f:ajax /> Regions <f:ajax> <h:panelGrid> <h:inputText id=”text1”/> <h:commandButton id=”button1” /> </h:panelGrid> </f:ajax> Ajax applied to “text1” and “button1”. Ajax not applied to panelGrid : no default event associated with it.
    61. 61. Enhancing JSF 2.0 Components Adding Ajax <ul><li>Method 1: <f:ajax/> in composite component implementation </li></ul><cc:interface...> … </cc:interface> <cc:implementation...> … <h:commandButton id=”button1” value=”login”> <f:ajax /> </h:commandButton> … </cc:implementation>
    62. 62. Enhancing JSF 2.0 Components Adding Ajax <ul><li>Method 2: JSF Ajax api call in script </li></ul><cc:implementation...> … <h:commandButton id=”button1” value=”login” onclick=”return myscript.login(' #{cc.clientId') , event);”/> </h:commandButton> … </cc:implementation> script.js: myscript.login=function login( componentId , event) { jsf.ajax.request (document.getElementById(subButton), event);
    63. 63. Enhancing JSF 2.0 Components Behaviors <ul><li>Additional functionality applied to components
    64. 64. Ajax is a behavior (AjaxBehavior)
    65. 65. Not just about Ajax </li><ul><li>Tool tips, client validation, … </li></ul></ul>
    66. 66. Enhancing JSF 2.0 Components Behaviors : Client Behavior(s) <ul><li>New type of attached object
    67. 67. Attached by “event”
    68. 68. Contributes script content for rendering </li><ul><li>AjaxBehavior is a Client Behavior that formulates the jsf.ajax.request script content for rendering </li></ul><li>All Html standard components implement ClientBehaviorHolder interface </li></ul>
    69. 69. Enhancing JSF 2.0 Components Adding Behaviors <ul><li>Similar to adding Ajax... </li></ul><cc:interface..>...</cc:interface> <cc:implementation> <h:graphicImage value...> <be:tip event=”mouseover”/> <be:tip event=”mouseout/> </h:graphicImage> be:tip is custom behavior
    70. 70. Other Enhancements <ul><li>Navigation </li><ul><li>Implicit Navigation : navigation logic in page (instead of faces-config xml)
    71. 71. Conditional Navigation : more complex navigation rules </li></ul><li>Exceptions </li><ul><li>Central Exception Handler subscribes to exception events
    72. 72. Can be decorated </li></ul><li>EL : enhancements for component processing: </li><ul><li>#{component} #{compositeComponent}
    73. 73. #{component.clientId} </li></ul></ul>
    74. 74. Other Enhancements <ul><li>Validation </li><ul><li>Integration with JSR 303: Bean Validation
    75. 75. <f:validateRequired> <f:validateRegexp> </li></ul><li>New Scopes </li><ul><li>“Conversation” : from Contexts and Dependency Injection (JSR 299)
    76. 76. “Flash” </li><ul><li>useful for storing data for use on the “next” request
    77. 77. Single view transition </li></ul><li>“ View” </li><ul><li>Longer than request ; shorter than session
    78. 78. State preserved until interaction with current view complete </li></ul></ul></ul>
    79. 79. Other Enhancements <ul><li>Annotations </li><ul><li>Managed Bean
    80. 80. Component (and associated artifacts) </li><ul><li>@FacesComponent, @FacesRenderer
    81. 81. @FacesConverter, @FacesValidator
    82. 82. @FacesBehavior </li></ul></ul></ul>
    83. 83. Summary Java EE 6 GlassFish v3 <ul><li>JSF 2.0 : Big improvements address community needs </li><ul><li>Easier component development
    84. 84. Ajax : Dynamic Components
    85. 85. Less configuration
    86. 86. Performance (State Saving) </li></ul></ul>
    87. 87. Resources Java EE 6 and GlassFish v3 Java EE 6 <ul><li>Java EE 6 Home
    88. 88. java.sun.com/javaee
    89. 89. Java EE 6 Downloads </li></ul>java.sun.com/javaee/downloads <ul><li>Upcoming Training </li></ul>java.sun.com/javaee/support/training <ul><li>Sun GlassFish Enterprise Server v3 Home </li><ul><li>www.sun.com/glassfishv3 </li></ul><li>Community Page </li><ul><li>glassfish.org </li></ul><li>The Aquarium Blog </li></ul>blogs.sun.com/theaquarium <ul><li>White Papers/Webinars
    90. 90. http://www.sun.com/glassfish/resources </li></ul>GlassFish
    91. 91. New JSF 2.0 Training and Certification Java EE 6 GlassFish v3 <ul><li>Brand new training course and certification for JSF 2.0 </li><ul><li>Developing Web Applications using JSF Technologies (SL-340-EE6) – 3 Days </li></ul><li>Includes coverage of: </li><ul><li>Using JSF within a Web Container
    92. 92. Designing views using JSF, EL, and custom components using Facelets
    93. 93. Integrating external resources such as JPA within Web Applications
    94. 94. Testing, packaging and deploying applications and more </li></ul><li>Register your interest! </li><ul><li>https://dct.sun.com/dct/forms/reg_us_1611_480_0.jsp </li></ul></ul>
    95. 95. Q&A

    ×