2008-11-21 28 views
0

我正在使用struts 1.1和tile。如何在Struts action class中设置一个tile的主体URL?

我有一个定义瓷砖像

<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> 

我希望能够定身参数的值,在我的Java Action类。 我会从ActionMapping或ActionForm获得什么来做到这一点?

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

的支柱配置文件看起来像

<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> 

谢谢


由我想出了以下解决方案

在定义的页面接受的答案启发瓷砖def我有以下

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

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

在动作类(因为我懒)我有以下

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

和它的工作。

回答

0

您可能想要查看控制器类的图块支持。瓷砖高清输入将是这个样子:

<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> 

那么YourControllerClass将实现perform()方法,如:

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"); 
     } 

    } 
} 

上面的例子可以直接在你的动作来完成,无需使用TilesControllers的,但TilesController可以帮助减少你的操作混乱。不管技术的总体目标是参数化NM_Landing.jsp,然后实际更改定义的“body”属性使用哪个jsp。例如,NM_landing.jsp可能只不过是包含一些类似于

<c:import url="${nameOfJSPToImport}" /> 
相关问题