JSP 嵌套< nested:equal>和< nested:write>组合

mfuanj7w  于 2022-12-07  发布在  其他
关注(0)|答案(2)|浏览(229)

Basically, my question is simple but it requires someone that knows Struts 1.1 and is still alive.
What I try to build looks like this in Pseudo-Code:

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

The whole thing would happen inside a iteration. So here what is currently working but not yet the goal:

<nested:equal property="method1" value="true">
    <nested:write property="prop1" /> 
</nested:equal>

<nested:notEqual property="method1" value="true">
    <nested:write property="prop1" />
</nested:notEqual>

Now what really drives me crazy is that this works as well:

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

But whenever I insert something between the two inner nested:equal tags it wont compile.
So my final solution (see below) wont compile complaining "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>

After about 4 hours I still don't have a idea how I could manage this so any suggestions would be really appreciated and helps even 2 weeks after this post because my next step is to dig into Struts 1.1 Documentation.

hc2pp10m

hc2pp10m1#

虽然Roman C的解决方案工作得很好,但我也设法将它与嵌套标记放在一起。
很遗憾,我不允许发布原始源代码,但这是什么&它是如何工作的,现在:

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

lsmd5eda2#

用途

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

相关问题