1 / 40

What's New In Struts 1.1 Session TU07 – 11/19/2002 – 13:30-14:30 Craig R. McClanahan Senior Staff Engineer Sun Microsyst

What's New In Struts 1.1 Session TU07 – 11/19/2002 – 13:30-14:30 Craig R. McClanahan Senior Staff Engineer Sun Microsystems, Inc. Session Outline. Welcome New Features In Struts 1.1 What Does The Future Hold? Q&A. Welcome. Welcome. I'm assuming you are familiar with Struts 1.0

filomena
Download Presentation

What's New In Struts 1.1 Session TU07 – 11/19/2002 – 13:30-14:30 Craig R. McClanahan Senior Staff Engineer Sun Microsyst

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. What's New In Struts 1.1 Session TU07 – 11/19/2002 – 13:30-14:30 Craig R. McClanahan Senior Staff Engineer Sun Microsystems, Inc.

  2. Session Outline • Welcome • New Features In Struts 1.1 • What Does The Future Hold? • Q&A

  3. Welcome

  4. Welcome • I'm assuming you are familiar with Struts 1.0 • For an introduction, please attend session WE06 tomorrow at 1:30pm: “Building Web Applications With Struts” • Two BOFs tonight will also be of interest: • 8pm – Struts After 1.1 – Where Do We Go From Here? • 9pm – JSP New And Improved – The JSP 2.0 Specification

  5. Welcome • Struts 1.0: • Original Release: June 2001 • Version 1.0.2: February 2002 • Struts 1.1: • Version 1.1-b1: March 2002 • Version 1.1-b2: September 2002 • Version 1.1 Final: “Real Soon Now”

  6. Welcome • The “Struts community” is growing • Users • STRUTS-USER has 2399 subscribers • Second only to TOMCAT-USER (2454) • Downloads: • October 2002: 29,199 • Tomcat runs 80k-100k per month • Articles and Books: • Five recently published • http://jakarta.apache.org/struts/resources/ • So What's New In Struts 1.1?

  7. New Features In Struts 1.1

  8. New Features In Struts 1.1 • Jakarta Commons Libraries • DynaActionForm • Declarative Exception Handling • PlugIn API • STRUTS-NESTED Tag Library • STRUTS-EL Tag Library (Contrib) • Application Module Support

  9. Jakarta Commons Libraries • Small, tightly focused, class libraries • Several originated in Struts 1.0 • Included Libraries: • Beanutils – JavaBean manipulation • Collections – Extensions to JDK collections • Dbcp – JDBC connection pools • Digester – XML file parsing • Fileupload – HTML file upload support • Lang – Extensions to JDK class libraries • Logging – Wrapper around log implementations • Pool – Object pools (used by DBCP) • Validator – Field validation framework

  10. COMMONS-BEANUTILS • Generic JavaBean property manipulation • Originally from Struts 1.0 • New features: • Pluggable type converters • Mapped properties: • Contact.phone(Work) • DynaBean interface and basic implementations • Dynamically defined sets of properties • BeanUtils and PropertyUtils transparently support DynaBeans and standard JavaBeans • Struts implementation: DynaActionForm

  11. COMMONS-BEANUTILS public interface DynaBean { public Object get(String name); public Object get(String name, int index); public Object get(String name, String key); public void set(String name, Object value); public void set(String name, int index, Object value); public void set(String name, String key, Object value); }

  12. COMMONS-DBCP • Provides javax.sql.DataSource (connection pool) implementation • Connection timeouts • Both getConnection() methods supported • Idle connections can be released • Validation query tests connection before return • For backwards compatibility, org.apache.struts.util.GenericDataSource is a wrapper around DBCP. • FYI: Tomcat 4.1 also uses this implementation.

  13. COMMONS-FILEUPLOAD • Original code from Turbine • Supports file uploads as defined by RFC 1867. • For backwards compatibility, org.apache.struts.upload.MultipartUploadHandler implementations wrap this.

  14. COMMONS-LOGGING • Wrapper around any logging API • Intelligent discovery mechanism • Did I ask for a specific factory? Use it. • Is Log4J available? Use it. • Is JDK 1.4 logging available? Use it. • Fallback to default logger • Simple System.err logging implementation is available • Relies on underlying logging implementation for configuration

  15. COMMONS-VALIDATOR • Original code from Struts • General framework for validating input data against defined rules • Struts Integration: • ValidatorActionForm and DynaValidatorActionForm • Configure Validator via Plug-In Architecture

  16. DynaActionForm • A common user complaint: writing ActionForm beans is a pain • Now, in many cases you will not have to! • Only necessary to provide non-default reset() and/or validate() methods • Configure the properties and their types in your struts-config.xml file • Transparently supported by all of the existing Struts machinery

  17. DynaActionForm <form-bean name="logonForm" type="org.apache.struts.action.DynaActionForm"> <form-property name="username" type="java.lang.String"/> <form-property name="password" type="java.lang.String"/> </form-bean>

  18. Declarative Exception Handling • Previously, an Action had to deal with all business logic exceptions itself • Now, you can choose to delegate exception handling to other application resources • Global and per-Action mapping declared in struts-config.xml (like forwards): • From a particular Exception class or superclass • To an application-relative path • Requires a small change to your Action to leverage this feature ...

  19. Declarative Exception Handling public ActionForward execute (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { ... throw new PasswordExpiredException(...); ... }

  20. Declarative Exception Handling <action path="/logon" ...> ... <exception key="expired.password" type="o.a.s.w.e.ExpiredPasswordException" path="/changePassword.jsp"/> ... </action>

  21. PlugIn API • Before, you had to subclass ActionServlet (or define a separate servlet) to initialize application resources at startup time • Now, you can declare a PlugIn that receives notification of application startup and shutdown public interface PlugIn { public void destroy(); public void init(ActionServlet servlet, ApplicationConfig config) throws ServletException; }

  22. STRUTS-NESTED Tag Library • If you ever programmed in Pascal, you might remember the "with" statement ... • Nested tags allow you to establish a default bean for nested property references • 1:1 correspondence, and identical functionality, of other Struts tags • Except the "name" property gets set for you automatically ...

  23. STRUTS-NESTED Tag Library • Before using the nested tags: <bean:write property="address.city"/> <bean:write property="address.state"/> <bean:write property="address.zip"/> • After using the nested tags: <nested:nest property="address"> <nested:write property="city"/> <nested:write property="state"/> <nested:write property="zip"/> </nested:nest>

  24. STRUTS-EL Tag Library • Inspired by the expression language that is available in the JSP Standard Tag Library. • ${customer.address} • ${customer.address[0].city} • ${cusotmer.addressMap['Postal']} • Includes “EL-ized” versions of all Struts tags that do not have natural replacements in the JSTL tag library. • Nearly every tag attribute supports EL. • Shipped in the “contrib” subdirectory, not currently integrated into Struts core.

  25. STRUTS-EL Tag Library • Requires a Servlet 2.3 / JSP 1.2 container • Such as Tomcat 4.x or later • Requires the “standard” taglib from the Jakarta Taglibs project • http://jakarta.apache.org/taglibs/doc/standard-doc/intro.html

  26. Application Module Support • Very popular user request for large scale applications • Design goals: • Support multiple independent struts-config.xml files in the same webapp • Modules are identified by an "module prefix" that follows the context path • Existing Struts-based applications should be able to be installed individually, or as a module, with no changes to the pages, Actions, form beans, or other code

  27. Application Module Support • Implications of the design goals: • "Default" module with a zero-length prefix (like the ROOT context in Tomcat) • "Context-relative" paths must now be treated as "module-relative" • ActionServlet initialization parameters migrate to the struts-config.xml file • Controller must identify the relevant module, and make its resources available (as request attributes)

  28. Application Module Support • The goals appear to have been achieved: • Please download the latest nightly build and help us by testing your apps as modules • Current restrictions: • All requests must flow through the controller – no direct hyperlinks to JSP pages with Struts tags • Can be lifted by implementing the controller as a Filter in Servlet 2.3 • Works only for extension-mapped paths to the controller servlet (*.do)

  29. What Does The Future Hold?

  30. What Does The Future Hold? • In the mean time, the Java world around web applications is changing ... • Servlet 2.4 (JSR-154) • JSP 2.0 (JSR-152) • JSP Standard Tag Library 1.0 (JSR-52) • JavaServer Faces (JSR-127) • And new things are becoming popular ... • Web services • Portals

  31. Servlet 2.4 • Some nice additions • Request lifecycle events • Request dispatcher events • But not likely to affect Struts in the near term • However, it may soon be time to migrate Struts to be based on Servlet 2.3 (and JSP 1.2) or later • Filters and lifecycle listeners • Request and response wrappers • JSP Standard Tag Library ...

  32. JavaServer Pages (JSP) 2.0 • Expression Language • Available now in JSP Standard Tag Library • In JSP 2.0, can use in all tag attributes, as well as in template text • We can help the transition by supporting this in Struts tags • JSP Fragments • Create parameterized "custom actions"

  33. JSP Standard Tag Library (JSTL) 1.0 • Version 1.0 released, June 2002 • RI based on code from Jakarta • http://jakarta.apache.org/taglibs/ • Core library has familiar functionality • URL, XML, and I18N tags also very useful • Expression language allows for much simpler tags • JSP containers can optimize performance • Struts users should definitely planon utilizing these tag libraries

  34. JavaServer Faces • A frequently asked question this year: • What's the deal with Struts and JavaServer Faces? • The short version of the answer: • JavaServer Faces will be a useful mechanism to build the UI for Struts-based web applications • For the longer version of the answer, let's go back into history for a moment ...

  35. JavaServer Faces • Where did Struts come from? • Two years of discussion about MVC and Model 1 versus Model 2 • My experience building a large scale web application that was fully internationalized • The key feature – separation of concerns • The key technologies enforcing separation • Logical name mappings in struts-config.xml • View --> Controller encapsulated in a form submit, matched to a form bean • Controller --> View via RequestDispatcer

  36. JavaServer Faces • Where is JavaServer Faces coming from? • The need to provide rich UI components to page developers • The need for a standard set of components to ease learning (and enable tools support) • But UI components are not enough by themselves: • Event handling • Validation • Navigation • There needs to be enough there to beusable out of the box

  37. JavaServer Faces • So what do we do about the overlap? • Use the parts that are helpful, ignore the parts that are not • The planned scenario: • Struts provides a JSF-compliant tag library that provides the functionality we know and love • Context-relative paths, URL rewriting, ... • Struts applications can migrate their UI to use Faces, one page at a time, with no changes to the Actions, form beans, or business logic • This is an entirely feasible endgame • Will be available with next EA release of JSF ...

  38. Resources

  39. Struts Resources • The Struts and Commons Web Sites: • http://jakarta.apache.org/struts/ • http://jakarta.apache.org/commons/ • Recent Books About Struts: • Cavaness, Chuck; Programming Jakarta Struts; O'Reilly • Goodwill, James; Mastering Jakarta Struts; John Wiley • Husted, Ted; Java Web Development With Struts; Manning • Spielman, Sue; The Struts Framework: Practical Guide for Programmers; Morgan Kaufman • Turner, James; Struts Kick Start; Sams

  40. Q & A

More Related