我有以下数据表。
<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>
即使行数等于flightList
,它也不显示单元格内的任何数据。尺寸。
当我将其替换为 <ui:repeat>
时,然后显示数据。
<ui:repeat value="#{flightReservation.flightList}" var="value">
<h:outputText value="#{value.fromPlace}" />
<h:outputText value="#{value.toPlace}" />
</ui:repeat>
这是怎么造成的,如何解决?
最佳答案
我曾经遇到过同样的行为,这只是变量范围的问题:
你是说,行数是正确的,但内容没有显示。您正在将变量命名为 flight
我假设具有此名称的值已在标记中较早使用过,甚至用作 <ui:param>
。
数据表现在正在迭代(内部)并生成正确数量的行,但是当它尝试访问 fligt
的属性时jsf 引用了之前声明的变量,但找不到属性 fromPlace
, toPLace
等等
尝试重命名您的变量,看看这是否可以解决您的问题。
下面的示例将生成 stringList.size()
次yoloyolo,即使人们希望显示列表的内容。如果列表源由对象组成,则对属性的任何实例访问都将失败,因为 yoloylo 不是预期类型的对象。
<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>
关于jsf - :dataTable renders rows correctly but does not show cell values while ui:repeat does,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26832153/