【问题标题】:How can use <s:if> tag in Struts 2?如何在 Struts 2 中使用 <s:if> 标签?
【发布时间】:2013-07-30 10:01:07
【问题描述】:

我有下面的 Struts 2 标签,我需要检查属性 value="#attr.row.Commentaire 是否不为空,如果不是,则显示一个小图标,用户可以单击它并查阅属性 value="#attr.row.Commentaire 的内容。

如何有效地使用 Struts 2 的 &lt;s:if&gt; 标签来做到这一点?

<display:column title="Commentaire" sortable="true" sortProperty="Commentaire"
    class="alerte_td_commentaire">              
<s:property value="#attr.row.Commentaire"/>

【问题讨论】:

    标签: java jsp struts2 displaytag ognl


    【解决方案1】:

    使用以下代码

    <s:if test="#attr.row.Commentaire != null && #attr.row.Commentaire != ''">
    

    if tag 使用test 属性将OGNL 表达式计算为布尔值。

    您可能还想使用一个a tag 来呈现一个HTML 锚标记,该标记可以与if 标记结合使用来

    查阅属性的内容

    还有一个 debug 标记,可用于包装其他标记,以显示将呈现调试数据的链接。

    <s:debug>  
     <s:property value="%{#attr.row.Commentaire}"/>
    </s:debug>
    

    【讨论】:

    • 在我的 if 子句之后,我添加了 效果很好并显示了一个图标,如果可以添加在 onclick 图标上激活的 javascript 以显示 value="%{#attr.row.Commentaire}" 的值,我会感到很困惑??
    • @john 您应该编写onclick 处理程序并使用alert('&lt;s:property value="%{#attr.row.Commentaire}"/&gt;'); 或使用javascript 框架将UI 小部件应用于处理程序。如果您想将值从服务器传递到客户端,无论如何混合这样的 java 和 javascript 是可行的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多