0

Im trying to display a simple table with an @Entity infos using the following tag-libs:

xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"

Here's the mapped entity attribute, a boolean:

@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.: by debugging the backing bean, im getting the desired list.

Here's my .xhtml (jsf page) snippet:

<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>

Altough the list is not empty, the empty message is being shown, and no row is displayed.

If i force the row displaying, removing the conditional rendering, i get the following error:

java.lang.IllegalArgumentException: Cannot convert 1 of type class java.lang.Long to class java.lang.Boolean

for the property active.

I've tried a few solutions before asking, like these:

How does Java expression language resolve boolean attributes? (in JSF 1.2)

javax.el.PropertyNotFoundException when trying to resolve Boolean properties in EL

Update 1: reviewing my code, i realised i was empty testing an object, not a list, updating my snippet also, so, the conditional on the rows displaying its ok now, but the active property issue, still throwing the error.

Community
  • 1
  • 1
vcorrea
  • 101
  • 2
  • 8
  • It throws the same exception, also tried changing the datatype to String, wich displayed **true**, by using the EL `#{u.active}`, but using `#{u.active == 'true'}` as the condition, doesnt return true, at least, it doesnt throw any error. – vcorrea May 28 '14 at 17:15
  • jsf snippet: `#{u.active} | #{u.active == 'true'} | active ` displays: `true | true | ` – vcorrea May 28 '14 at 17:20

1 Answers1

1

The problem is that JSF tags (e.g. ui:repeat) are evaluated in a different (later) phase then JSTL tags (e.g. c:when). Therefore the values of your user list are just not available when the c:when statement is evaluated. Sometimes this results in a weird behaviour so that it looks like the values are available. Have a look at this answer to get some details.

You should use the rendered attribute of some JSF component:

<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>

turns into:

<h:panelGroup rendered="#{u.active}">
  <span style="color: green" class="glyphicon glyphicon-ok"></span>
</h:panelGroup>
<h:panelGroup rendered="#{not u.active}">
  <span style="color: red" class="glyphicon glyphicon-remove"></span>
</h:panelGroup>

You can also use it for values like this:

<h:outputText rendered="#{u.active}" value="#{u.name}" />

See also:

Community
  • 1
  • 1
unwichtich
  • 13,712
  • 4
  • 53
  • 66
  • Perfect! Thought about using rendered, based on recent studies, but since i havent been using jsf for a long time, im still getting used to new stuff. Thanks for the great answer, and references! – vcorrea May 28 '14 at 18:08