1 / 46

Michael Rimov Centerline Computers Craig McClanahan Sun Microsystems O’Reilly Open Source Convention July 7 - 11, 2003

Michael Rimov Centerline Computers Craig McClanahan Sun Microsystems O’Reilly Open Source Convention July 7 - 11, 2003. Introduction. Presentation Slides, Notes and Samples Available At: http://www.centercomp.com/beyondstruts/. What Defines Struts?.

gryta
Download Presentation

Michael Rimov Centerline Computers Craig McClanahan Sun Microsystems O’Reilly Open Source Convention July 7 - 11, 2003

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Michael RimovCenterline ComputersCraig McClanahanSun MicrosystemsO’Reilly Open Source ConventionJuly 7 - 11, 2003

  2. Introduction Presentation Slides, Notes and Samples Available At:http://www.centercomp.com/beyondstruts/

  3. What Defines Struts? • Lightweight Model 2 J2EE framework for the HTTP Servlet portion of the application. • NOT Meant to dictate the entire J2EE implementation.

  4. Model 2 Typical Flow MVC Based Model 2 Architecture Diagram

  5. Abbreviated Model

  6. What Makes Struts So Extensible? • Lightweight and Focused: Doesn’t Try To Do Everything. • Well Designed: Very good separation of concerns, very clean coding implementation. • Uses Java Reflection to allow freedom of objects.

  7. Case Studies

  8. Case Studies • Struts and Expresso • Struts and Macromedia Flash • Struts and XML • Struts and Java Server Faces

  9. Case Study: Expresso 5http://www.jcorporate.com/

  10. Case Study: Expresso 5

  11. Case Study: Expresso 5 Controller Extension: • Provided Application Level Security Matrix • Added in-request routing ability. • Provided mostly-Servlet Independent flow of control.

  12. Case Study: Expresso 5 Struts Action: public ActionForward perform( ActionMapping mapping,ActionForm form, HttpServletRequest request, HttpServletResponse response) Expresso Version: protected void runPromptLoginState(ControllerRequest request, ControllerResponse response)

  13. Case Study: Expresso 5 Model Extension: • ControllerRequest / ControllerResponse objects. • ControllerResponse is populated with Inputs/Outputs/Blocks/Transitions. • Can use Struts Beans as well. • Added Database Access Layer

  14. Case Study: Expresso 5 View Extension: • Default UI Renderer • Customizable XSLT Processing Capabilities. • Compatible with Struts Views.

  15. Case Study: Expresso 5 Integration Experiences: • Extremely supportive community • Reaped Performance Improvements • Partial Integrations still work well. • Easy to extend even the Struts internals.

  16. Case Study:Macromedia Flashhttp://www.macromedia.com/software/flash

  17. Case Study: Macromedia Flash

  18. Case Study: Macromedia Flash Integration Methods: • XMLSocket and XML formatted pages. • LoadVariables and property formatted pages. • NOT covering Flash Remoting All Integration methods need some sort of template view system such as JSP or Velocity.

  19. Case Study: Macromedia Flash Start Page • Tell Flash Where To Get Its Data. <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="445" height="244"> <param name="movie" value=“mymovie.swf?data=http://www.example.org/MyAction.do&next=http://www.example.org/NextAction.do"> <param name="quality" value="high"> <embed src=“mymovie.swf?data=http://www.example.org/MyAction.do&next=http://www.example.org/NextAction.do"quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="445" height="244"></embed> </object>

  20. Case Study: Macromedia Flash XML Socket Method • Create Flash Starting Page • Load initial data through the ‘data’ parameter. • On-submit, the movie opens an XML Socket to the server and Struts. • Struts formats return data as XML.

  21. Case Study: Macromedia Flash XML Socket Method: Drawbacks • XML Parsing on the Client Side. • XML Parsing on the Server Side • Expansion of Bandwidth

  22. Case Study: Macromedia Flash Load Variables Method • Create Flash Starting Page • Load initial data through the ‘data’ parameter. • On-submit, the movie opens an http request to the server. • Struts formats return data in a “property=value” format.

  23. Case Study: Macromedia Flash Load Variables Method: Drawbacks • Simple format of return data only. • Fancier formats require parsing again. Similar drawbacks as XMLSocket. • Recommended you use simple beans for rendering only • Flash 6 Only

  24. Quick ActionScript Sample on (release) { LoadVars lv = new LoadVars(); LoadVars receiveVars = new LoadVars(); lv.loginName=LoginName; lv.password = Password; receiveVars.onLoad = processResult; //Not Shown Here lv.sendAndLoad(data,receiveVars,"POST"); }

  25. Introducing Craig McClanahan

  26. Case Study: Struts and XML

  27. Case Study: Struts and XML • Most Struts apps generate HTML • With the Struts HTML tags (JSP) • With alternative presentation systems like Velocity and Freemarker • Templates accessed via RequestDispatcher. forward() call, but there's another way ... • Action.execute() -- return null to indicate that the response has been created already • Opens the door to XML-based output

  28. Struts and XML: General Approach • Form submitted to Action, as usual • Action creates result beans, as usual, or renders XML objects • Action renders XML directly (or forwards to an XML-generating template) • Template incorporates dynamic data from result beans or rendered XML objects • XSLT stylesheet(s) transform to HTML or other markup language

  29. Struts and XML: Resources • JSP and JSTL can be used directly instead of HTML tags • Two Popular Struts and XML Extensions: • StrutsCX • Http://it.cappuccinonet.com/strutscx/ • Stxx • http://www.openroad.ca/opencode/ • More information online, on the Struts Resources pages: • http://jakarta.apache.org/struts/resources/

  30. Case Study: Struts andJavaServer Faces

  31. Case Study: JavaServer Faces • What Is JavaServer Faces? • Server-side user interface component framework for Java-based web apps • Under development in the Java Community Process (JSR-127) • Currently at Public Draft 2 in the process • Early Access 4 of Reference Implementation is available • http://java.sun.com/j2ee/javaserverfaces/

  32. JavaServer Faces: Goals • Accessible to corporate developers • Usable via tools and by hand • Usable with and without JSP • Usable with and without HTML • Usable with servlet and portlet APIs • Can be adopted immediately • Minimum platform: Servlet 2.3, JSP 1.2 • Final 1.0 version: 4QCY2003

  33. JavaServer Faces: Features • Extensible UI component model • Flexible rendering model • Standard HTML renderkit included • Event and listener model • Validation framework • Basic page navigation support • Internationalization and accessibility

  34. JavaServer Faces: Sample Page <f:use_faces> <h:form formName=”logonForm”> <h:panel_grid columns=”2”> <h:output_text value=”Username:”/> <h:input_text id=”username” length=”16” valueRef=”logonBean.username”/> <h:output_text value=”Password:”/> <h:input_secret id=”password” length=”16” valueRef=”logonBean.password”/>

  35. JavaServer Faces: Sample Page <h:command_button type=”submit” label=”Log On” actionRef=”logonBean.logon”/> <h:command_button type=”reset” label=”Reset”/> </h:panel_grid> </h:form> </f:use_faces>

  36. JavaServer Faces: Managed Bean <managed-bean> <managed-bean-name> logonBean </managed-bean-name> <managed-bean-class> mypackage.mybeans.LogonBean </managed-bean-class> <managed-bean-scope> request </managed-bean-scope> </managed-bean>

  37. JavaServer Faces: Bean Class public class LogonBean { // No base class! // The usual property getters/setters public String getUsername() { ... } public void setUsername(String username) { ... } public String getPassword() { ... } public void setPassword(String password) { ... }

  38. JavaServer Faces: Bean Class ... // Getter returns “Action” for button public Action getLogon() { // Anonymous inner class used here return new Action() { public String invoke() { // Invoke method on bean class return (logon()); } }; }

  39. JavaServer Faces: Bean Class ... protected String logon() { // Business logic can access form fields // as instance variables if (username/password combo is ok) { return (“success”); // Logical outcome } else { return (null); } } }

  40. JavaServer Faces: Navigation <navigation-rule> // Wildcard and global patterns ok <from-tree-id> /logon.jsp </from-tree-id> <navigation-case> <from-action-ref> // Optional logonBean.logon </from-action-ref> <from-outcome> // Optional success </from-outcome> <to-tree-id> /mainmenu.jsp </to-tree-id> </navigation-case> </navigation-rule>

  41. JavaServer Faces and Struts • So, is JavaServer Faces Replacing Struts? • NO!!! • Struts 1.1 is and remains very popular • Struts will continue to innovate & advance • Then, can I use them together? • YES!!! • With the Struts-Faces Integration Library • http://jakarta.apache.org/builds/jakarta-struts/ release/struts-faces/

  42. JavaServer Faces And Struts • Replaces Struts HTML Tags With More Powerful JavaServer Faces Components • Continue to use struts-config.xml file • Integrates with Struts RequestProcessor • Supports Standard Struts Features: • Form Beans and Actions • Validator Framework • Tiles Framework (coming soon ...)

  43. JavaServer Faces and Struts • To use the library with an existing app: • Get the JavaServer Faces RI • Drop it and struts-faces.jar into your /WEB-INF/lib directory • Change HTML tags on one page at a time • Tweak your forward paths, and • Don't touch your form beans or actions • MVC works ... what a concept :-).

  44. Conclusion

  45. Presentation Information Michael Rimov: rimovm@centercomp.com Craig McClanahan:craigmcc@apache.org Slides, Notes and Sample Code Available http://www.centercomp.com/beyondstruts/

More Related