Refactoring: Move logic from JSP page to Action and tiles

Discussions

J2EE patterns: Refactoring: Move logic from JSP page to Action and tiles

  1. [logic:equals value="true" name="valid"]
     [logic:equals value="assigned" name="status"]
      [logic:equals value="admin" name="access"]
        Some HTML
      [/logic:equals]
     [/logic:equals]
    [/logic:equals]

    |
    V

    [tiles:useAttribute name="canShowHtml" /]
    [logic:equals value="true" name="canShowHtml"]
      Some HTML
    [/logic:equals]

    Mechanics

    1. Define state subgroupings on paper
    2. Define state groupings on paper
    3. Define additional local forwards based on the groupings in struts-config.xml
    4. Define extensions to the page in your tiles-config.xml
    5. Convert the single return mappings.findForward("page") to break it up into conditions that will send to the appropriate forward
    6. Define which sections should be shown and not shown in your tiles-config.xml
    7. If sub-tiles are used. Rename the tiles defintion for the subtile and make the original definition include the new subtile definition. This is to get around Tiles not passing in context data to its subtiles.
    8. Add [tiles:useAttribute] for the attributes that define which sections can be seen to the JSP page.
    9. Replace the multiple logic sections with a single [logic:equals]
    10. Remove old forward from struts-config.

    Full sample is available at http://www.trajano.net/2005/10/refactoring-move-presentation-logic.html
  2. Thanks for the formulation of the actual procedure. Just what a refactoring should be. I'd also like to see one for moving things to templates (velocity style) as well if someone were familiar enough with that to go through the step by step process.