【发布时间】:2014-07-18 00:00:59
【问题描述】:
我正在尝试使用以下标签库显示带有@Entity 信息的简单表格:
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
这是映射的实体属性,一个布尔值:
@NotNull
@Column(name = "ACTIVE", columnDefinition = "BIT", length = 1)
private boolean active;
//... getters and setters
public boolean getActive() {
return active;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active= active;
}
ps.:通过调试 backing bean,我得到了想要的列表。
这是我的 .xhtml(jsf 页面)sn-p:
<ui:repeat var="u" value="#{usersList}">
<tr>
<td>#{u.name}</td>
<td>#{u.login}</td>
<td>#{u.email}</td>
<td>
<c:choose>
<c:when test="${u.active}">
<span style="color: green" class="glyphicon glyphicon-ok"></span>
</c:when>
<c:otherwise>
<span style="color: red"
class="glyphicon glyphicon-remove"></span>
</c:otherwise>
</c:choose>
</td>
</tr>
</c:when>
</ui:repeat>
尽管列表不为空,但显示的是空消息,并且没有显示任何行。
如果我强制显示行,删除条件渲染,我会收到以下错误:
java.lang.IllegalArgumentException: Cannot convert 1 of type class java.lang.Long to class java.lang.Boolean
对于属性active。
在询问之前我已经尝试了一些解决方案,例如:
How does Java expression language resolve boolean attributes? (in JSF 1.2)
javax.el.PropertyNotFoundException when trying to resolve Boolean properties in EL
更新 1:查看我的代码,我意识到我是 empty 测试一个对象,而不是一个列表,同时更新我的 sn-p,所以,条件行现在显示正常,但 active 属性问题,仍然抛出错误。
【问题讨论】:
-
它抛出了同样的异常,还尝试将数据类型更改为字符串,显示 true,使用 EL
#{u.active},但使用#{u.active == 'true'}作为条件,不返回 true,至少,它不会抛出任何错误。 -
jsf sn-p:
<td>#{u.active} | #{u.active == 'true'} | <c:if test="${u.active == 'true'}"> active </c:if></td>显示:true | true |
标签: jsf-2.2 glassfish-4 java-ee-7