2

Facelet:

<h:dataTable value="#{item1.zapas}" var="item2" >
    <h:column>
        <h:outputText value="#{item2.hrac == null}"/>
        <c:choose>
            <c:when test="#{item2.hrac == null}">
                <h:outputText value="X"/>
            </c:when>
            <c:when test="#{item2.hrac != null  }">
                <h:outputText value="#{item2.vysledok}"/>
            </c:when>

        </c:choose>
    </h:column>
</h:dataTable>

Output:

trueX
falseX

falseX
trueX

item.hrac is sometimes null and sometimes not null but in my choose it still choice null. So what is wrong? How can I solve it?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
hudi
  • 15,555
  • 47
  • 142
  • 246

1 Answers1

2

JSTL tags and JSF tags doesn't run in sync as you'd expect from the coding. JSTL tags runs during JSF view build time only and the result is a tree of only JSF tags. JSF tags runs during view render time only and the result is a tree of only HTML elements.

When it's JSTL's turn to run during view build time, the #{item2} is not available in the scope simply because JSF hasn't run at that point.

To overcome this, you want to use JSF rendered attribute instead. Get rid of the whole <c:choose> block and put the following in place:

<h:outputText value="X" rendered="#{item2.hrac == null}" />
<h:outputText value="#{item2.vysledok}" rendered="#{item2.hrac != null}" />

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555