How can I set the url of a tile body in a Struts action class?

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 can I get from ActionMapping or ActionForm for 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


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

On the page defined in the tile definition, 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.

0


source to share


1 answer


You might want to look at table support for controller classes. The subdivision element will 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 your control controller will 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 can be done directly in your Activity without using TilesControllers, but TilesController can help make your activities less cluttered. The overall goal, regardless of method, is to parameterize NM_Landing.jsp and then actually change which jsp uses the body attribute to define. For example NM_landing.jsp can be nothing more than a call to something like

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

      

0


source







All Articles