WebSphere Portal
IBM Struts Portlet Framework


Readme for the SPFLegacyTiles sample

Introduction

The Apache Struts framework includes a powerful framework called Tiles. The Tiles framework allows setting up the view or render of the application to define areas, or tiles. The Tiles example is a simple banking application that uses these tiles for the defining the view. Some of the tiles always display the same information while other areas in the sample change. Tiles support requires a request processor that implements the function defined in the Apache Struts Tiles request processor. The Struts Portlet Framework supplies a SPF specific Tiles request processor that must be used for Tiles support.

Sample details and code snippets

The sample has several screens. The layout of all of the screens are the same; only the body and the navigation tiles change. The sample requires the SPF Tiles request processor. The following is from the Struts configuration file and shows the plugin to register the request processor.

  <!-- add the Tiles plugin. -->
  <plug-in className="com.ibm.wps.portlets.struts.plugins.WpsStrutsTilesPlugin">
    <set-property property="definitions-config" value="/WEB-INF/conf/tiles-def.xml"/>
    <set-property property="definitions-parser-details" value="2"/>
    <set-property property="definitions-parser-validate" value="true"/>    
  </plug-in>

Controller Class

The example also demonstrates the use of a controller class. The controller class is called before the page renders. This feature is similar to the IStrutsPrepareRender interface, in which an action can be invoke before rendering. The controller class can be used to set up the rendering and will be executed each time the view is displayed.

  <tiles-definitions>
    <definition name="tiles.example.base" page="/layouts/base.jsp" 
                controllerClass="com.ibm.wps.example.struts.tiles.actions.SetupController">
      <put name="title"      value="Tiles Example" />
      <put name="banner"     value="/tiles/banner.jsp"/>
      <put name="navigation" value="/tiles/navigation.jsp"/>
      <put name="menu"       value="/menu.do"/>
      <put name="body"       value="/tiles/body.jsp" />
    </definition>

The controllerClass is this example just sets a request attribute.

  public class SetupController implements Controller 
  {
    /**
      * The <code>Log</code> instance for this application.
     */
    private Log log = LogFactory.getLog(SetupController.class);
    
    public void perform (ComponentContext tileContext,
                         HttpServletRequest request, 
                         HttpServletResponse response,
                         ServletContext servletContext)
    throws ServletException, IOException
    {
      log.debug("This is from the Setup Controller");
      Object obj = request.getAttribute("setup");
      if (obj == null)
      {
        request.setAttribute("setup","setup controller was called");
      }
      else
      {
        request.setAttribute("setup","setup controller called more than once");
      }
    }
  }

Summary

The SPFLegacyTiles example demonstrates how to set up a Tiles application in the Struts Portlet Framework. The Tiles framework is a powerful framework that allows creating a standard display of the application, where only certain tiles need to be modified for different views.