I have the following data table.
<h:dataTable value="#{flightReservation.flightList}" var="flight">
<h:column>
<h:outputText value="#{flight.fromPlace}" />
</h:column>
<h:column>
<h:outputText value="#{flight.toPlace}" />
</h:column>
</h:dataTable>
It does not show any data inside the cells, even though the number of rows is equal to the flightList
size.
When I replace it by <ui:repeat>
, then it shows the data.
<ui:repeat value="#{flightReservation.flightList}" var="value">
<h:outputText value="#{value.fromPlace}" />
<h:outputText value="#{value.toPlace}" />
</ui:repeat>
How is this caused and how can I solve it?
I encountered the same behaviour once and it was simply an issue with the scope of variables:
You are saying, that the number of rows is correct, but the content not displayed. You are naming the variable flight
and I assume that a value with this name has been used earlier in your markup or even used as a <ui:param>
.
The Datatable is now iterating (internal) and generating the correct amount of rows, but when it tries to access the properties of fligt
jsf refers to the earlier declared variable and fails to find the properties fromPlace
, toPLace
etc.
Try to rename your variable and see if this solves your issue.
The example bellow would produce stringList.size()
times yoloyolo even if one would expect the content of the list to be shown. And if the listsource is made out of objects, any instance access on the attributes will fail cause yoloylo is not an object of the expected type.
<ui:param name="foo" value="yoloyolo" />
<h:dataTable value="#{backingBean.stringList}" var="foo">
<h:column>
<f:facet name="header">string</f:facet>
- #{foo}
</h:column>
</h:dataTable>