如何基于另一个属性在JSP中显示属性

时间:2014-05-08 14:13:42

标签: java jsp jstl

我有一个jsp,我正在显示一个像

这样的表

<tr class="even">                
<td><bean:write name="itemDetails" property="recived"/></td>                                         
<td><bean:write name="itemDetails" property="actioned"/></td>
<td> <bean:write name="itemDetails" property="internalUser"/></td> 
<td> <bean:write name="itemDetails" property="action"/>   </td>
 </tr>  </logic:iterate>

此处操作的属性为格式为08/05/2014 14:34的日期。

现在我想显示属性internalUser for row如果actioned属性不超过6个月,那么隐藏它,有人可以帮忙如何继续吗?

1 个答案:

答案 0 :(得分:1)

itemDetails中创建另一个属性,例如

private boolean showInternalUser;

public boolean getShowInternalUser() {
   // compare difference between `actioned time` and `new Date()` here (6 months)
   // and return true if you need to display the property `internalUser`
}

public void setShowInternalUser(boolean showInternalUser) {
   this.showInternalUser = showInternalUser;
}

然后在jsp更改:

<td> <bean:write name="itemDetails" property="internalUser"/></td> 

<td>
   <c:if test="${itemDetails.showInternalUser}">
      <c:out value="${itemDetails.internalUser}"/>
   </c:if>
</td>