2008-11-21 26 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}" /> 
相關問題