JSF 2.0 (JavaEE Webinar)

Embed Size (px)

Citation preview

  • 1. JavaServer Faces 2.0 Overview Roger Kitain JSF Co-Specification Lead mailto:[email protected] http://www.java.net/blogs/rogerk/ https://twitter.com/rogerk09

2. Hi Level Categories of Features Foundational NewFeatures Large NewFeatures 3. System Events

  • Publish/Subscribe event model

4. JSF Lifecycle events 5. Listeners registered at 3 scopes:

  • Component: UIComponent.subscribeToEvent()

6. View: UIViewRoot.subscribeToEvent() 7. Application: Application.subscribeToEvent() Publish using:

  • Application.publishEvent()

Declarative component event listener registration: 8. Resources

  • No need for separate Filter or Servlet

9. Loaded from Classpath or filesystem 10. Library / i18n / Versioning Support 11. Java API:

  • @ResourceDependency ; @ResourceDependencies
  • Attributes: library name; resource name

12. Target Attribute: head, body, form Markup:

13. Resources 14. View Traversal

  • Multiple components in the view visited for a single traversal

15. Useful for component(s) processing 16. VisitContext

  • Specifies components to visit

17. createVisitContext() UIComponent.visitTree()

  • Performs component(s) visit

Usages: Ajax ; State Saving 18. Partial State Saving

  • JSF 1.x State Saving:
  • Tedious/error prone for component developers

19. Performance issues(session bloat) JSF 2.0: Partial State Saving

  • Only save what's changed since initial view creation

20. Per view state size up to 4 x smaller 21. Default for JSF 2.0 components (written with Facelets) 22. PartialStateHolder

  • signals when initial state is configured : markInitialState()

StateHelper

  • Storage map for component state (attributes,listeners,...)

23. No need for saveState/restoreState 24. GET Request Support View Parameters

  • Map incoming GET request parameter values to any EL bean/property

25. Mappings specified with component:

  • GET Request: page1.xhtml?user=johndoe

26. is EditableValueHolder

  • converters/validators can be used on view parameters

27. GET Request Support

  • Issue GET requests without hand coding destination URL

28. Uses JSF navigation system for determining destination

  • Destination determined at render time
  • Outcome mapped to target view identifier

Integrate with view parameters:

  • Can use to specify parameters too

29. JSF 2.0 Component Model Why Do We Need It?

  • With the 1.x component model too many artifacts, hooks:
  • Component class

30. Renderer 31. Tag class 32. Tld 33. faces-config.xml 34. ...... 35. JSF 2.0 Component Model

  • Powerful tools:
  • Templating

Facelets is the foundation

  • Optimized for JSF

36. XHTML and tags 37. Eliminates translation/compilation 38. Templating 39. Composite Components 40. JSF 2.0 Component Model

  • Facelets 2.0
  • Contains most of the standard Facelets features

41. Enhanced to work with JSF 2.0 component building

  • Easily attach listeners, validators, converters

42. Namespaces created automagically no more taglibs Supports Composite Components 43. It's in the specification ! 44. Composite Components

  • Turns page markup into a JSF UI component with attached validators, converters, listeners

45. True abstraction:

  • Reuseable component

Using Page (XHTML) Component (XHTML) 46. Composite Components

  • Convention over configuration
  • Resources dir; Library name is directory name;

47. Tag name is file name < my : outvalue=yes/> On disk: /resources/ comp / out .xhtml 48. Composite Components What's Inside The Black Box?

  • Interface
  • The usage contract

49. Everything page author needs to know to use component Implementation

  • Markup used to create component

50. Composite Components resources/ezcomp/LoginPanel.xhtml ...

Username:
Password:

.... 51. Composite Components resources/ezcomp/LoginPanel.xhtml ...

Username:
Password:

.... 52. Composite Components Using Page xmlns:ez=" http://java.sun.com/jsf/composite/ezcomp ">

53. Enhancing JSF 2.0 Components

  • Other prominent JSF 2.0 additions:
  • Ajax

54. Behaviors Work well with composite components 55. Enhancing JSF 2.0 Components Ajax

  • JavaScript api in the specification
  • jsf.ajax.request .....

56. Useful for making JSF Ajax calls from JavaScript 57. Control component processing on the server and component rendering at the client 58. Enhancing JSF 2.0 Components Ajax: Declarative Solution :

  • Serves two roles depending on placement:
  • Nested within single component
  • ajaxifies that component

Wrapping approach tag is placed around a group of components

  • ajaxifies all components that support the events attribute

59. Enhancing JSF 2.0 Components Ajax: Declarative Solution : Do exactly the same thing since action is the default event for commandButton components. JavaScript events supported too. 60. Enhancing JSF 2.0 Components Ajax: Declarative Solution : Regions Ajax applied to text1 and button1. Ajax not applied to panelGrid : no default event associated with it. 61. Enhancing JSF 2.0 Components Adding Ajax

  • Method 1: in composite component implementation

62. Enhancing JSF 2.0 Components Adding Ajax

  • Method 2: JSF Ajax api call in script

script.js: myscript.login=function login( componentId , event) { jsf.ajax.request (document.getElementById(subButton), event); 63. Enhancing JSF 2.0 Components Behaviors

  • Additional functionality applied to components

64. Ajax is a behavior (AjaxBehavior) 65. Not just about Ajax

  • Tool tips, client validation,

66. Enhancing JSF 2.0 Components Behaviors : Client Behavior(s)

  • New type of attached object

67. Attached by event 68. Contributes script content for rendering

  • AjaxBehavior is a Client Behavior that formulates the jsf.ajax.request script content for rendering

All Html standard components implement ClientBehaviorHolder interface 69. Enhancing JSF 2.0 Components Adding Behaviors

  • Similar to adding Ajax...

... be:tip is custom behavior 70. Other Enhancements

  • Navigation
  • Implicit Navigation : navigation logic in page (instead of faces-config xml)

71. Conditional Navigation : more complex navigation rules Exceptions

  • Central Exception Handler subscribes to exception events

72. Can be decorated EL : enhancements for component processing:

  • #{component}#{compositeComponent}

73. #{component.clientId}