tags:

views:

404

answers:

1

I am using struts 1.1 with tiles.

I have tiles with definitions like

<definition name="cnmp.body.index" extends="cnmp.mainLayout" >
  <put name="title"  value="CNM Portal" />
  <put name="bodytitle"  value="Home" />
  <put name="body"   value="/00-CNM_Landing.jsp" />
</definition>

I want to be able to set the value of the body parameter in my java Action class. What would I get from the ActionMapping or ActionForm to do this?

public class TileForwardAction extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm arg1,
        HttpServletRequest arg2, HttpServletResponse arg3) throws Exception
{
    return mapping.findForward("theTile");           
}
}

the struts config file looks like

  <action-mappings>

  <action  path = "/index"
     type = "com.bellsouth.snt.cnmp.ui.action.TileForwardAction"
   scope = "request"
         input = "cnmp.body.index"
         parameter= "theTile"
    >    
      <forward name="theTile" path="cnmp.body.index"/>       
  </action>

Thank you


Inspired by the accepted answer I came up with the following solution

In the page defined in the tile def I have the following

<% String destAttr=(String)request.getAttribute("dest"); %>

<jsp:include page="<%=destAttr%>" flush="true" />

In the action class (because I was lazy) I have the following

    request.setAttribute("dest", "landingB.jsp");

And it worked.

A: 

You might want to look into tiles support for Controller Classes. The tiles def entry would look something like this:

<definition 
  name="cnmp.body.index" 
  extends="cnmp.mainLayout"
  controllerClass="org.yourpackage.YourControllerClass">
  <put name="title"  value="CNM Portal" />
  <put name="bodytitle"  value="Home" />
  <put name="body"   value="/00-CNM_Landing.jsp" />
</definition>

then the YourControllerClass would implement the perform() method like:

public class YourControllerClasss implements Controller
    public void perform(ComponentContext context,
      HttpServletRequest request,
      HttpServletResponse response,
      ServletContext servletContext)
      throws ServletException, IOException {

      //some logic to determine what the 'body' should be

      if (service.isUp()){
        request.setAttribute("nameOfJSPToImport", "/jsps/import-me.jsp");
      }else{
        request.setAttribute("nameOfJSPToImport", "/jsps/import-me-instead.jsp");
      }

    }
}

The above example could be done directly in your action without use of TilesControllers, but the TilesController can help make your Actions less cluttered. The overall goal regardless of technique is to parameterize the NM_Landing.jsp then actually changing which jsp the "body" attribute of the definition is using. For example, NM_landing.jsp could be nothing more than include call something like

<c:import url="${nameOfJSPToImport}" />
Brian