基本上,我的问题很简单,但需要有人知道Struts 1.1并且还活着。
我尝试构建的内容在伪代码中看起来像这样:
IF element.method1 = true THEN
IF element.method2 = true THEN
COLOR.GREEN, PRINT element.prop1
ELSE
COLOR.RED, PRINT element.prop1
END
ELSE
COLOR.BLACK, PRINT element.prop1
END
整个事情都会在迭代中发生。所以这里目前正在运作但目标还不是:
<nested:equal property="method1" value="true">
<nested:write property="prop1" />
</nested:equal>
<nested:notEqual property="method1" value="true">
<nested:write property="prop1" />
</nested:notEqual>
现在让我疯狂的是,这也是有效的:
<nested:equal property="method1" value="true">
<nested:equal property="method2" value="true">
</nested:equal>
</nested:equal>
<nested:notEqual property="method1" value="true">
<nested:write property="prop1" />
</nested:notEqual>
但每当我在两个内部nested:equal
标签之间插入内容时,它就不会编译。
所以我的最终解决方案(见下文)不会编译抱怨"Missing Endtag for nested:write."
<nested:equal property="method1" value="true">
<nested:equal property="method2" value="true">
<nested:write property="element.prop1" />
</nested:equal>
</nested:equal>
<nested:notEqual property="method1" value="true">
<nested:write property="element.prop1" />
</nested:notEqual>
大约4个小时后,我仍然不知道如何管理这个,所以任何建议都会得到真正的赞赏,甚至在这篇文章后2周也会有所帮助,因为我的下一步是深入研究Struts 1.1文档。
答案 0 :(得分:0)
使用
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
,代码看起来像
<c:choose>
<c:when test="${element.method1 == true}">
<c:choose>
<c:when test="${element.method2 == true}">
<span style="color:green;"><c:out value="${element.prop1}/></span>
</c:when>
<c:otherwise>
<span style="color:red;"><c:out value="${element.prop1}/></span>
</c:otherwise>
</c:choose>
</c:when>
<c:otherwise>
<span style="color:black;"><c:out value="${element.prop1}/></span>
</c:otherwise>
</c:choose>
答案 1 :(得分:0)
虽然Roman C的解决方案完美无缺,但我还设法将它与嵌套标签结合在一起。
遗憾的是,我不允许发布原始来源,但是这就是&amp;它现在如何运作:
<nested:form action="/someReq" styleClass="standard">
<nested:present property="myBean.genList">
<nested:iterate property="myBean.genList" indexId="index">
<nested:equal property="method1" value="true">
<nested:equal property="method2" value="true">
<strong class="green">
<nested:write property="prop1" />
</strong>
</nested:equal>
<nested:notEqual property="method2" value="true">
<strong class="red">
<nested:write property="prop1" />
</strong>
</nested:notEqual>
</nested:equal>
<nested:notEqual property="method1" value="true">
<nested:write property="prop1" />
</nested:notEqual>
</nested:iterate>
</nested:present>
</nested:form>