Saturday, September 12, 2009

JSF - Answers to Apache Struts

Java Server Faces is a component oriented and event driven framework for web applications. It is extensible, standard specification. This component driven model have given hope of role playing in web appliation development.
  • Page Author can independently design a web page with easy to use tools backed by extensive tag library. 
  • Application developers integrates UI design with event, valiation, convertor and objects. 
  • Component Writer can write new components in extensible and customizable nature. 
  • Architect can independently define navigation, ensure scalability of applicability and configure bean obj registration. 
  • Tool Vendors can independently develop tools to make design of web a easy experience with intuitive drag-n-drop features
Trade-offs: 
JSP/Servlet: Lack of
  • UI component
Struts: Lack of
  • UI component model
  • Event model 
  • State Management 
  • Support for multiple render 
  • Standard 
Technology Orientation: 
  • JSF - View / Separate controller
  • Servlet - View/Controller combined   
  • Struts - Controller 
But JSF and Struts can coexist. It will be suitable for application which already has struts impl and take advantage of UIComponent of JSF. 

 Building Blocks
  • Component 
  • Event listener
  • Validator 
  • Back-end data integration
API Stack
  • JSF Tag and API
  • JSP 1.2
  • Servlet 2.3
Life-cycle of JSF:  



1. Restore View Phase
  • FacesContext - Build view of JSF/wires event handlers and validator. 
    • New Req - Create empty view
    • Middle Req - Restores the view state from client/server
2. Apply Request Value Phase 
  • decode Method - 
    • Extracts values from Req parameters for all UI Component 
    • Type conversion to all component
3. Process Validation Phase 
  • Validates all extracted values to all components 
    • Error - Queue it on FacesContext and advance the lifecycle to Render Response Phase. 
4. Update Model Value Phase 
  • Updates/Assign server-side object with corresponding component's local value 
  • Type conversion from component to model properties
5. Invoke Application Phase 
  • Invokes any application-level events
    • Invoke ActionListener Impl (success action) 
    • Pass outcome to NavigationHandler (default)
    • Navigation Rule (config file) - Match outcome to response view 
    • JSF - Set response view to page
6. Render Response Phase 
  • encode Method: 
    • Renders components from component tree of FacesContext 
    • Create appropriate markup for component tree 
    • Save the state of response
Info About JSF:
  • UI Component Model 
    • Rendering Model, Event and listerner model, conversion model and validation model .
  • Configuration File: 
    • faces-config.xml 
  • Types of Event: 
    • ActionEvent 
    • ValueChangeEvent 
    • PhaseEvent
  • Types of localization 
    • Static data
    • Dynamic data
    • Messages
  • Steps for Static localization 
    • Create ResourceBundle
    • Ref bundle from pages 
    • Ref the localized messages within bundle 
  • Important Top Classes  
    • For view: Parent is UIView
    • For component: UIComponent
JSF Component:
  • Standard Component:
    • UIForm - represents a user input form that is a container of other components.
    • UICommand - represents UI components like buttons, hyperlinks and menu items.
    • UIInput - represents UI components like text input fields, numeric input fields.
  • Custom Component:
    • User/Developer designed component on top of standard components as well as other custom component.
    • Great feature of JSP is power to use third party components seamlessly. How to create custom component?
    • Either implement UIComponent interface or extend UIComponentBase class to bring default behavoiur of component
Type of Tag Library:

    References: 

    0 comments:

    Post a Comment