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


i'm trying use <c:if> conditionally put <h:outputlink> inside <h:datatable> when state finished.

<h:datatable value="#{bean.items}" var="item" width="80%">     <h:column>         <f:facet name="header">             <h:outputtext value="state" />         </f:facet>          <c:if test="#{item.state != 'finish'}">             <h:outputtext value="missing value" />         </c:if>         <c:if test="#{item.state == 'finish'}">             <h:outputlink value="mylink">                 <h:outputtext value="value = #{item.state}" />             </h:outputlink>         </c:if>     </h:column> </h:datatable> 

but not work, why , how can fix it?

jstl tags evaluated during building of view, not during rendering of view. can visualize follows: whenever view tree created first time, jstl tags executed , result view jsf components. whenever view tree rendered, jsf components executed , result html. so: jsf+jstl doesn't run in sync you'd expect coding. jstl runs top bottom first, hands result jsf , it's jsf's turn run top bottom again. may lead unexpected results in jsf iterating components uidata because row data (in particular case #{item} object) not available while jstl runs.

in nutshell: use jstl control flow of jsf component tree building. use jsf control flow of html output generation.

you want use 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:


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -