如何在Struts 2中使用if标签?

时间:2013-07-30 10:01:08

标签: java jsp struts2 displaytag ognl

我是Struts2的新手。我有以下Struts2标记,我需要检查属性value="#attr.row.Commentaire是否为空,如果不是,则显示一个小图标,用户可以单击该图标并查阅属性value="#attr.row.Commentaire的内容。如何有效地使用Struts2的if标签呢?

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

1 个答案:

答案 0 :(得分:0)

使用以下代码

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

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

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

  

查阅该物业的内容

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

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