JSTL c:if doesn’t work inside a JSF h:dataTable

JSTL tags are evaluated during building of the view, not during rendering of the view. You can visualize it as follows: Whenever a view tree get created for the first time, all JSTL tags are executed and the result is a view with only JSF components. Whenever a view tree get rendered, all JSF components get executed and the result is HTML. So: JSF+JSTL doesn’t run in sync as you’d expect from the coding. JSTL runs from top to bottom first, hands the result to JSF and then it’s JSF’s turn to run from top to bottom again. This may lead to unexpected results in JSF iterating components like UIData because the row data (in your particular case the #{item} object) is not available while JSTL runs.

In a nutshell: Use JSTL to control flow of JSF component tree building. Use JSF to control flow of HTML output generation.

You want to use the rendered attribute here.

<h:outputText value="Missing value" rendered="#{item.state ne 'Finish'}" />
<h:outputLink value="myLink" rendered="#{item.state eq 'Finish'}">
    <h:outputText value="Value = #{item.state}" />
</h:outputLink>

See also:

Leave a Comment