【问题标题】:how to access properties in the test attribute of a struts if tag如何访问struts if标签的test属性中的属性
【发布时间】:2011-04-03 21:48:48
【问题描述】:

我正在迭代一个名为“分类”的 bean 数组。如何访问标签中的 parentID 属性?我试过 %{parentID} 但这不起作用。

<s:iterator value="classifications" status="theStatus">
    <s:if test="%{parentID} == -1">
        <p>-1: <s:property value="subjectName" /></p>
    </s:if>
    <s:else>
        <p>not -1: <s:property value="subjectName" /></p>
    </s:else>
</s:iterator>

【问题讨论】:

    标签: java jsp struts2 iterator


    【解决方案1】:

    我认为你需要这样的东西:

    <s:iterator value="classifications" status="theStatus" id="c">
        <s:if test="#c.parentID == -1">
            <p>-1: <s:property value="#c.subjectName" /></p>
        </s:if>
        <s:else>
            <p>not -1: <s:property value="#c.subjectName" /></p>
        </s:else>
    </s:iterator>
    

    根据您使用的 struts 版本,您可能需要将迭代器标签中的 id 属性更改为 var。

    【讨论】:

      【解决方案2】:

      我不使用 Struts2,但在普通 JSP EL 中,表达式仅在花括号内部进行评估。这也是有道理的。例如。 &lt;c:if test="${parentID == -1}" /&gt;。看看它是否有助于在您的 Struts2 标记中做同样的事情。快速浏览一下their documentation,我知道确实应该是这样。

      【讨论】:

        猜你喜欢
        • 2012-01-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-02-14
        相关资源
        最近更新 更多