从Struts 1.3/Tiles 1.x组合迁移到Struts 2/Tiles 3。但这真的是一个瓷砖问题
以前在定义中支持bean声明以支持菜单项的功能,Tiles 3显然已经放弃了这一点。所以我转换了这个:
<definition name=".selectPatient.menu" path="/WEB-INF/templates/menu.jsp">
<putList name="items">
<bean classtype="org.a.m.s.jsp.MenuItem">
<set-property property="id" value="menubar_register"/>
<set-property property="name" value="menubar_register"/>
<set-property property="title" value="Register"/>
<set-property property="onclick" value="registerPatient()"/>
<set-property property="text" value="Register"/>
<set-property property="roles" value="BASIC,LEAD,SUPER"/>
</bean>
<bean classtype="org.a.m.s.jsp.MenuItem">
<set-property property="id" value="menubar_multitransaction"/>
<set-property property="name" value="menubar_multitransaction"/>
<set-property property="title" value="Post Multiple Transactions"/>
<set-property property="onclick" value="postMultiTransactions()"/>
<set-property property="text" value="Post Multiple Transactions"/>
<set-property property="roles" value="BASIC,LEAD,SUPER"/>
</bean>
</putList>
</definition>
和相应的menu.jsp页面:
<logic:iterate id="item" name="items" type="org.a.m.s.jsp.MenuItem">
<%if (UserRoles.userHasRole(request,item.getRoles())){%><td><table id="button_<bean:write name="item" property="id"/>" cellpadding="0" cellspacing="0" border="0"><tr><td><img src="images/menu_button_round_edge_left2.gif"></td>
<td style="border-top:1px white solid; border-bottom:1px white solid;">
<a name="<bean:write name="item" property="name"/>" id="<bean:write name="item" property="id"/>" accesskey="M" title="<bean:write name="item" property="title"/>" class="menuItem" href="#" isDisabled="false" onclick="if (this.isDisabled != 'true'&&isPageReady()) <bean:write name="item" property="onclick"/>;"
onmouseover="if (this.isDisabled != 'true'&&isPageReady())document.getElementById('button_<bean:write name="item" property="id"/>').style.backgroundColor='#ffff99';" onmouseout="if (this.isDisabled != 'true'&&isPageReady())document.getElementById('button_<bean:write name="item" property="id"/>').style.backgroundColor='#000066';"><bean:write name="item" property="text"/></a></td>
<td><img src="images/menu_button_round_edge_right2.gif" width="9" height="17"></td>
</tr></table></td>
<%}%>
</logic:iterate>
迁移到
- 定义:
<definition name="defaultMenuComponent" template="/WEB-INF/templates/barbutton.jsp">
</definition>
<definition name="menubar_register" extends="defaultMenuComponent">
<put-attribute name="id" value="menubar_register" cascade="true"/>
<put-attribute name="name" value="menubar_register" cascade="true"/>
<put-attribute name="title" value="Register" cascade="true"/>
<put-attribute name="onclick" value="registerPatient()" cascade="true"/>
<put-attribute name="text" value="Register" cascade="true"/>
<put-attribute name="roles" value="BASIC,LEAD,SUPER" cascade="true"/>
</definition>
<definition name="menubar_multitransaction" extends="defaultMenuComponent">
<put-attribute name="id" value="menubar_multitransaction" cascade="true"/>
<put-attribute name="name" value="menubar_multitransaction" cascade="true"/>
<put-attribute name="title" value="Post Multiple Transactions" cascade="true"/>
<put-attribute name="onclick" value="postMultiTransactions()" cascade="true"/>
<put-attribute name="text" value="Post Multiple Transactions" cascade="true"/>
<put-attribute name="roles" value="BASIC,LEAD,SUPER" cascade="true"/>
</definition>
<definition name=".selectPatient.menu" template="/WEB-INF/templates/menu.jsp">
<put-list-attribute name="items">
<add-attribute value="menubar_register" type="definition"/>
<add-attribute value="menubar_multitransaction" type="definition"/>
</put-list-attribute>
</definition>
- 将所有的构造逻辑推入barbutton.jsp:
<table id="button_<tiles:insertAttribute name="id" flush="true"/>" cellpadding="0" cellspacing="0" border="0">
<tr>
<td><img src="images/menu_button_round_edge_left2.gif"></td>
<td style="border-top:1px white solid; border-bottom:1px white solid;">
<a name="<tiles:insertAttribute name="name" flush="true"/>" id="<tiles:insertAttribute name="id" flush="true"/>" accesskey="M" title="<tiles:insertAttribute name="title" flush="true"/>" class="menuItem" href="#" isDisabled="false" onclick="if (this.isDisabled != 'true'&&isPageReady()) <tiles:insertAttribute name="onclick" flush="true"/>;" onmouseover="if (this.isDisabled != 'true'&&isPageReady())document.getElementById('button_<tiles:insertAttribute name="id" flush="true"/>').style.backgroundColor='#ffff99';" onmouseout="if (this.isDisabled != 'true'&&isPageReady())document.getElementById('button_<tiles:insertAttribute name="id" flush="true"/>').style.backgroundColor='#000066';"><tiles:insertAttribute name="text" flush="true"/>
</a>
</td>
<td><img src="images/menu_button_round_edge_right2.gif" width="9" height="17"></td>
</tr>
</table>
- menu.jsp的更改如下:
<tilesx:useAttribute id="items" name="items" classname="java.util.List"/>
<table border=0 cellpadding=0 cellspacing=1>
<tr>
<c:forEach items="${items}" var="listItem">
<td>
<tiles:insertDefinition name="${listItem}" flush="true"/>
</td>
</c:forEach>
</tr>
</table>
并且它不起作用,得到java.lang.StackOverflowError
尝试各种不同的方法
1条答案
按热度按时间gk7wooem1#
发现问题-将菜单定义重命名为.definition以与包含的属性区分开。