Sunday, October 18, 2009

Recipe 1.4. Upgrading from Struts 1.1 to Struts 1.2










Recipe 1.4. Upgrading from Struts 1.1 to Struts 1.2




Problem



You want to upgrade an application based on Struts 1.1 to Struts 1.2.





Solution



  1. Download the Struts 1.2 binary distribution from http://struts.apache.org/acquiring.html.

  2. Copy the JAR files and
    Tag Library Descriptor (TLD)
    files from the Struts lib folder to your
    application's WEB-INF/lib
    folder.

  3. If you use absolute URIs for the taglib directives
    in your JSP pages, change these to use the new URIs shown in Table 1-4.


Table 1-4. Struts 1.1 and 1.2 Taglib URIs

Struts 1.1 Taglib URI



Struts 1.2.4 Taglib URI



http://jakarta.apache.org/struts/tags-bean



http://struts.apache.org/tags-bean



http://jakarta.apache.org/struts/tags-html



http://struts.apache.org/tags-html



http://jakarta.apache.org/struts/tags-logic



http://struts.apache.org/tags-logic



http://jakarta.apache.org/struts/tags-template



http://struts.apache.org/tags-template



http://jakarta.apache.org/struts/tags-tiles



http://struts.apache.org/tags-tiles



http://jakarta.apache.org/struts/tags-nested



http://struts.apache.org/tags-nested





  1. Change the DOCTYPE declaration at the beginning of your
    validation.xml file(s) to the following:

    <!DOCTYPE form-validation PUBLIC 
    "-//Apache Software Foundation//DTD Commons Validator Rules Configuration
    1.1.3//EN" "http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd">


  2. Change the DOCTYPE declaration at the beginning of your
    struts-config.xml file(s) to the following:

    <!DOCTYPE struts-config PUBLIC 
    "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
    "http://struts.apache.org/dtds/struts-config_1_2.dtd">


  3. Replace your use of the ActionError class with the
    ActionMessage class.

  4. Replace your use of the ActionErrors class with
    the ActionMessages class except within the
    validate( ) method of any custom
    ActionForms.

  5. Remove reliance on any init-param elements on the
    ActionServlet other than the
    config parameters. These parameters were
    deprecated in Struts 1.1 and are no longer supported in Struts 1.2.
    Instead, move these parameter values to your
    struts-config.xml file. Most of these parameters
    are replaced by attributes of the controller
    element.

  6. Remove reliance on the name,
    scope, and type attributes of
    the html:form tag. These attributes were
    deprecated in Struts 1.1 and are no longer supported in Struts 1.2.




Discussion



The formal goal of Struts 1.2 was to remove deprecated methods and
complete support for modules. Though Struts 1.2
doesn't make sweeping changes to the Struts core as
Struts 1.1 did, it includes new features and enhancements that are
worth the effort of upgrading. Many of these features are discussed
throughout this book. Here are some of the most significant
enhancements:



  • New validwhen
    Validator rule for complex cross-field validations (Recipe 8.4)

  • Wildcard
    action mappings that allow you to reuse
    action
    elements for multiple related URLs (Recipe 7.8)

  • New prebuilt actions including a new
    MappingDispatchAction class and a locale-switching
    LocaleAction (Recipes Section 6.10
    and Section 12.4)


For a new application, you should use Struts 1.2. If you have an
existing Struts 1.1 application, you will find that Struts 1.2
introduces a number of new and useful features. In comparison to
migrating from Struts 1.0 to Struts 1.1, upgrading to Struts 1.2 is
less intrusive and requires less code changes.





See Also



The Struts wiki has additional details on this upgrade. The relevant
wiki page can be found at http://wiki.apache.org/struts/StrutsUpgradeNotes11to124.












    No comments:

    Post a Comment