2

我正在尝试根据module当前处于活动状态的页面来修改页面的外观。所以基本上,我有一组通用的 jsp 页面,需要根据模块更改图块。

我能够使用每个模块独立实现基本图块。这需要我在 jsp 中指定 tile 的定义。所以我的问题是,我怎样才能更改定义,从而使图块根据模块动态更改。

我正在使用带有 Struts 1.1 的 Tiles(不是我的选择,但要求是这样的),并且是这个框架的新手。

编辑:我试过浏览文档,浏览其他论坛和博客,但没有遇到类似的事情。有没有其他方法可以实现这一点,可能不需要切换磁贴定义?

4

1 回答 1

2

我从您的问题中了解到的是,您将在 tiles-defs.xml 文件中为 1 个 JSP 定义 2 个定义。像

<definition name="outputPage" extends="mainLayout">
    <put name="title" value="HELLO" />
    <put name="body"   value="/pages/Welcome.jsp" />
</definition>
<definition name="outputPage2" extends="mainLayout">
    <put name="title" value="HELLO2" />
    <put name="body"   value="/pages/tile2.jsp" />
</definition>

我建议实现您的要求的一种方法是在属性中设置模块类型(例如request.setAttribute("module", "module2");)。

假设您将在 struts-config.xml 中为同一个 JSP 页面进行 2 次转发。

    <action
            path="/Welcome"
            forward="/pages/tileTest.jsp"/>  
<action
            path="/customerAction"
            type="xyz.actions.CustomerAction"
            name="customerForm"
            scope="request">

            <forward name="tile" path="/Welcome.do"></forward>
            <forward name="customer" path="/pages/customer.jsp"></forward>
       </action>

然后在您的 JSP 页面(tileTest.jsp)中,这些图块将被定义为

    <%@page language="java" pageEncoding="shift-jis"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/struts-tiles" prefix="tiles" %>
<logic:notEmpty name="module">
<logic:equal name="module" value="module1">
<tiles:insert definition="outputPage" flush="true" />
</logic:equal>
</logic:notEmpty>

<logic:notEmpty name="module">
<logic:equal name="module" value="module2">
<tiles:insert definition="outputPage2" flush="true" />
</logic:equal>
</logic:notEmpty>

<logic:empty name="module">
<tiles:insert definition="outputPage" flush="true" />
</logic:empty>
于 2013-02-04T09:49:46.310 回答