Jsf Framework

3,173 views

Published on

Published in: Technology, Education
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,173
On SlideShare
0
From Embeds
0
Number of Embeds
18
Actions
Shares
0
Downloads
0
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Jsf Framework

  1. 1. JavaServer Pages™ /Servlets and Web Application Frameworks Doris Chen, Ph.D Staff Engineer This box provides space for call to Sun Microsystems, Inc action text, URLs, or any relevant info
  2. 2. Speaker’s Qualifications ● Doris Chen – Technology Evangelist at Sun Microsystems – Develops and delivers Code Camps for J2EE, Java performance tuning, J2ME and web services technologies for Sun Microsystems – Speaks around the world concerning Sun™ technologies
  3. 3. Presentation Agenda ● JSP™/Servlets Overview ● Frameworks • Struts • JavaServer™ Faces • Sun™ ONE Application Framework (JATO) ● Summary and Resources
  4. 4. How It Fits Together JSF S1AF JSTL Struts JSP™ java bean, expression lang.,custom tag lib Servlet session tracking, filtering, listener
  5. 5. Web Foundation: JSP™/Servlets ● Java Servlet technology since ’96, JSP 1.0 specification in June ’99 ● Servlets and JSP technologies: • JSP 1.2 and Java Servlet 2.3 technologies in the J2EE 1.3 platform (now) • JSP 2.0 and Java Servlet 2.4 technologies in the J2EE 1.4 platform (proposed final draft)
  6. 6. Java Servlet Technology ● Foundation for many technologies • The JAX-RPC API • Java portlet technology • The JAXM API • Struts, JavaServer Faces™, Sun™ ONE application framework ● Well understood by industry
  7. 7. The JavaServer Pages™ (JSP™) Specification ● JavaServer Pages technology: Building Block ● Mature spec ● Widely Used ● Many uses of Tag Libraries ● Very good community, look for the JSP 2.0 release
  8. 8. JSP Architecture Servlet Engine Client Request JSP Translator Redirect JSP Create Response Load JSP Servlet Servlet Load Servlet JSP Servlet
  9. 9. Frameworks Struts Sun™ ONE Application Framework JS L T SA 1F WAF JavaServer Faces™ (events) Server Client Request UI Response (markup)
  10. 10. Presentation Agenda ● JSP™/Servlets Overview ● Frameworks • Struts • JavaServer™ Faces • Sun™ ONE Application Framework (JATO) ● Summary and Resources
  11. 11. Jakarta Struts ● Struts is an open source framework developed by the Apache Jakarta project http://jakarta.apache.org/struts/ – Struts 1.02 is available and Struts 1.1 is in beta ● Struts allows: – JSP/Servlet developers to fashion their web applications using the MVC design pattern – Configure a lot of the default framework objects through xml configuration files – Run Servlet2.2/JSP1.1 container and above
  12. 12. Model-View-Control (model 2) MVC Design Pattern 1 Request (Controller) Servlet BROWSER In Redirect 3 st 2 an tia te 5 (View) (Model) Java Bean Response JSP 4 Servlet Container (EIS)
  13. 13. Struts: MVC Pattern Implemented Controller Model Action Action Mapping Action Servlet Request (xml) Client uses Response Action Action JSP View Forward Form Model Data View
  14. 14. Struts Components and Feature ● The View - a JSP or HTML page ● The Model - a Java object ( called a ActionForm) ● Central controller – ActionServlet • URI to ActionMapping(Action class) located in struts- config.xml file • Action classes • Adaptors between business layer and web tier ● Validation, Internationalization, Custom tags for creating HTML, presentation logic, and templating
  15. 15. Model ● Model classes should be coded independent of the Struts framework – Maximum code reusability by other applications ● Struts provides default Model components, most important one ActionForm • Create model class by extending the Struts ActionForm class ● Struts provides a org.apache.struts.util.PropertyUtils has a static method called copyProperties() – To copy all form properties to your original model object when your controller receives a form
  16. 16. Controller ● The controller is the switch board of MVC ● Directs the user to the appropriate views by providing the view with the correct model ● The task of directing users to appropriate views is called “mapping” ● Struts framework provides a base object called org.apache.struts.action.ActionServlet
  17. 17. Controller (Cont.) Http://myhost/authorize.do Server configured to pass *.do extensions to org.apache.struts.action.ActionServlet via a web.xml configuration file ActionServlet object inspects the URI and tries to match it against an ActionMapping located in the struts-config.xml file Instance of appropriate Action class is found and it’s perform() is called Action object handles the request and returns control to a view based where the user is within the flow of the application
  18. 18. struts-config.xml: ActionMapping <action-mappings> <action path="/logon" type="org.apache.struts.example.LogonAction" name="logonForm" scope="request" input="/logon.jsp"> </action> <forward name="success” path="/msgBoard.jsp"/> </action-mappings>
  19. 19. View ● ActionForward object tells JSP page to dispatch to ● The view in Struts is represented by JSP ● JSP can use ActionForm bean to get output Model data to display ● Struts contains a series of tag libraries – Facilitates communication between HTML designers and developers – Facilitates dynamic Web content
  20. 20. View: Example 1 <%@ page language="java" %> 2 <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> 3 <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> 4 <html:html locale="true"> 5 <head> 6 <title><bean:message key="logon.title"/></title> 7 <html:base/> 8 </head> ... 9 <html:errors/> 10 ... 11 <html:form action="/logon.do" focus="username"> 12 <table border="0" width="100%"> ... 13 <html:submit property="submit" value="Submit"/> 14 ... 15 </html:form> 16 ... 17 </html:html>
  21. 21. Struts Example Page 1 Jsp 1 Jsp 2 Jsp 3 Web Browser Web Server Form Request/session View Jsp Engine Bean Form 1 Bean Other Layer 2 Bean 1 Controller Struts- config. xml Mappings • path Action1 Action2 Action3 Action4 • action .java .java .java .java • [form bean] • [forwards] Business Business Business Business Bean 1 Bean 2 Bean 3 Logic Layer CoreSession CoreSession Socket Data MarkVision Server Layer
  22. 22. Presentation Agenda ● JSP™/Servlets Overview ● Frameworks • Struts • JavaServer™ Faces • Sun™ ONE Application Framework (JATO) ● Summary and Resources
  23. 23. JavaServer Faces Design Goals ● Tool Friendly ● Client device neutral ● Usable with JavaServer Pages (JSP) ● Usable without JSP ● Useful in today's lowest common denominator browsers ● Scalable
  24. 24. JavaServer Faces Requirements ● Extensible UI component model ● Flexible rendering model ● Comprehensive event model ● Powerful Validation framework ● Flexible error handling ● Basic page navigation ● Internationalization and Accessibility
  25. 25. How the JSF Specification Fits In JSF App JSF App JSF Tags JSP (1.2) JSF API Servlets (2.3)
  26. 26. JSF Architecture Server Request UI Client (Events) Response (Markup)
  27. 27. JSF Architecture Server JSF Page HTML Desktop HM TL Browser R d it en erK Front App ctrl JSF Page Backend WL M R d it en erK Phone WML
  28. 28. JSF Specification: Customers Application Extensions Tools Page Developer Author Component Developer JSF Application Implementor/ Developer Extender
  29. 29. Key JSF Concepts ● UIComponent – JavaBean like classes ─ Render-independent characteristics ─ Base class with standard behaviors ● Standard UIComponent Subclasses: ─ UICommand, UIForm, UIGraphic, UIInput, UIOutput, UIPanel, UISelectBoolean, UISelectMany, UISelectOne ● FacesEvent – Base class for request and application events ● Validator – Base class for standard and application defined validators
  30. 30. Key JSF Concepts ● Converter – Plug-in for String-Object conversion ● FacesContext – Per-Request State: ─ Servlet request, response, session ─ JSF request, response trees ─ Model reference expression evaluators • Syntax similar to the expression language of the JSP Standard Tag Library (JSTL) 1.0 • Primary interface between components and the data provided by (or to) the application
  31. 31. Key JSF Concepts ● Renderer – Converts components to and from a specific markup language ─ Supports render-dependent attributes on components ─ May support more than one component type ● RenderKit – Library of Renderers ─ Extensible at runtime ─ Basic HTML RenderKit is part of the specification
  32. 32. JSF Example 1 <%@ page language="java" %> 2 <%@ taglib uri="http:://java.sun.com/j2ee/html_basic" prefix="faces" %> 3 4 <jsp:usebean id="UserNumberBean” class=”NumberBean” scope=session> 5 <faces:usefaces> 6 <faces:form id="helloForm" forname="helloForm"> 7 <faces:textentry_input id="username" modelReference 8 ="UserNameBean.userName"> 9 10 <faces:command_button id="submitButton" label="submit"> 11 </faces:form> 12 </faces:usefaces> 13 ... 14 </html:html>
  33. 33. Component Tree HelloForm Input Form text UserName Submit event Stored Queued
  34. 34. Steps in Development Process ● Author the pages using the UI component tags • useBean tag • faces tags: • faces:form, faces:textentry_input, faces:command_button ● Develop the model objects, which will hold the data ● Develop navigation handlers • Define the navigation for the application by implementing ApplicationHandler class
  35. 35. Current Development Status ● Warning – everything above is subject to change! ● Under development in JSR-127 ─ Introduced at JavaOne US 2001 ● Large expert group ─ Framework developers, Tools providers, ISVs ● Completed Community Draft status (07/2002) ● Working towards Public Draft release of specification
  36. 36. Current Development Status ● Early Access of Reference Implementation is also available ● Early Access (pre-Public Draft) Specification available: • http://java.sun.com/j2ee/javaserverfaces/ ● JSF Public Forum: • http://forum.java.sun.com/forum.jsp?forum=427 ● JSF Comments: jsr-127- comments@sun.com ● Intranet Site: http://wspack.sfbay.sun.com/jsf
  37. 37. If You Only Remember One Thing… ● JavaServer Faces is destined to become the standard mechanism for creating user interface components for J2EE based web applications.
  38. 38. Presentation Agenda ● JSP™/Servlets Overview ● Frameworks • Struts • Sun™ ONE Application Framework (JATO) • JavaServer™ Faces ● Summary and Resources
  39. 39. Sun™ ONE Application Framework (JATO) Overview ● A J2EE application framework • Primarily focused on web tier • Leverage Sun Java Center J2EE Patterns ● Provide a robust, scalable application foundation • Application composition via reusable components • Full-featured event model and high-level tag library ● SOAP & Web Services support / integration ● Leveraged through Sun ONE Studio Wizard- based visual interfaces
  40. 40. Where can the Sun ONE Application Framework be used? ● Enterprises or ISV's building large enterprise web applications ● Large development team (10+) focused on web applications ● Few really know Java APIs at the web tier or enterprise tier
  41. 41. Sun ONE Application Framework (JATO) Platform Stack
  42. 42. S1AF and Your Application
  43. 43. J2EE Design Pattern ● Leverage Sun Java Center J2EE Patterns • Best practice design patterns for J2EE development • Fine grained patterns • Can be combined into a complete MVC ● Use Model View Controller pattern (MVC)
  44. 44. J2EE patterns used in S1AF ● Business delegate ● View helper ● Composite view ● Service to worker ● Front controller
  45. 45. Sun ONE Application Framework
  46. 46. Models ● Implements Business Delegate pattern – Reduce coupling between presentation tier clients and business services – Hides the underlying implementation details of business service (e.g. JDBC details) ● Provides developers a common interface for using any Enterprise resource – Web Service resources – Database resources – UIF (Enterprise Connectors) resources – J2EE Connector Architecture resources – AND 3rd party created
  47. 47. Views ● A union of JSP tags with S1AF view objects – S1AF JSPs use S1AF tags and othe 3rd party tags – S1AF views simply refer to model data ● Implements J2EE view helper pattern – S1AF views allows JSPs to remain Java-free – Presentation logic is placed in View class – More than one JSP can use a View Helper • Allows for variable content rendering ● Implements J2EE Composite View Pattern – S1AF view may be arbitrarily nested
  48. 48. JSP/View/Model Relationships
  49. 49. Controller ● Consistes of two patterns – Front controller – Service to workers ● Implements front controller pattern – All requests pass through front controller – Module servlet serves as front controller – Single point of entry allows for centralization of certain types of logic
  50. 50. Controller (Cont.) ● Implements ServiceToWorker pattern – Single service dispatches to request specific controllers(workers) • All requests pass through the FrontController • Controller logic can be partitioned into more fine grained units for scalability and logical partitioning – S1AF module servlet dispatches request to the appropriate worker (controller) • S1AF controller can be a Command interface • Developers will implement the command interface
  51. 51. Tool & Wizard Friendly
  52. 52. View Components ● “ Out of the box” Page components are available such as Button, Check Box, Combo Box ● 3rd party (SI’s) components can be dynamically added to the product
  53. 53. Component Story
  54. 54. Component Story
  55. 55. Component Story
  56. 56. Component Story
  57. 57. Component Story
  58. 58. Presentation Agenda ● JSP™/Servlets Overview ● Frameworks • Struts • JavaServer™ Faces • Sun™ ONE Application Framework (JATO) ● Summary and Resources
  59. 59. JSF, Struts and S1AF ● Focus is a bit different – Struts: encapsulates user-interface more at form or page level – JSF: UI components, component model for user-interface, Tools focus – S1AF: extends MVC and J2EE design pattern and comes with an extendable but ready-to use base implementation, visual builder tool ● Some overlap – Use the parts that are helpful, ignore the parts that are not – Pick solution best suited to expertise/task – JSF/Struts integration http://jakarta.apache.org/builds/jakarta-struts/nightly/struts- faces/
  60. 60. JSF, S1AF, and Struts ● All three communities are represented on JSR-127 expert group – The lead developer of Struts, Craig McClanahan, now works for Sun and is a member of JSF expert group – S1AF Architect is already participating in expert group meeting – Long term strategy: ● S1AF and struts will co-exists/merge with S1af evolving to use struts controller technology and JSF components ● Goal is to provide a single web-based framework also monetizes struts technology
  61. 61. Where to look further ● JSF http://java.sun.com/products/j2ee/javaserverfa ● Struts http://jakarta.apache.org/struts ● A good place to start is the S1AF-Tips group: http://groups.yahoo.com/group/iPlanet-JATO- Tips/ ● FAQ of the larger community forum at: http://groups.yahoo.com/group/iPlanet -JATO/ ● The Whitepaper: http://ias.red.iPlanet.com/jato ● You can get more information at: http://developer.iPlanet.com/tech/appserver/fr amework/index.jsp
  62. 62. JavaServer Pages™ /Servlets and Web Application Frameworks Doris Chen, Ph.D doris.chen@sun.com

×