![](/img/trans.png)
[英]How do I get h:outputText inside of a ui:repeat nested in h:dataTable to update when the datatable is updated?
[英]ui:repeat not working inside h:dataTable
我在h:dataTable
標記中的ui:repeat
有問題。 我有一個帶有字段名稱的集合,另一個帶有數據。 所以我按索引匹配它們。 當我加載頁面時,拋出OutOfBoundsException
異常。 但是當我在ui:repeat
之外放置了filingCabinetManagerBean.filingCabinet.schema.fields.indexOf(schemaField)
,它將顯示正確的索引。 因此,我嘗試將其拆分並聲明ui:param
和c:set
作為變量,但存在相同的問題。 cardData
屬性不為null也不為空,它具有7個項目,我已經調試了它。 那么您是否知道可能是什么問題?
PS:當我將ui:repeat
更改為h:dataTable
,它正在工作。 最棒的是,在另一個JSF頁面上使用了相同的構造並且可以正常工作,只有一個區別-我從在一個外部dataTable中引用的card獲取cardData
,所以它不是Bean(dot)
屬性,依此類推,但只有variable(dot)
依此類推。
有任何想法嗎? 謝謝您的幫助。 :)
<p:panel header="#{fileUploadBean.actualCard.id}">
<h:dataTable value="#{filingCabinetManagerBean.filingCabinet.schema.fields}" var="schemaField" style="vertical-align: top">
<h:column><h:outputText value="#{schemaField.fieldTitle}:" style="font-size: 20px;font-weight: bold"/></h:column>
<h:column>
<ul>
<ui:repeat value="#{fileUploadBean.actualCard.cardData.get(filingCabinetManagerBean.filingCabinet.schema.fields.indexOf(schemaField)).data}" var="data">
<li><h:outputText value="#{data.string}"/></li>
</ui:repeat>
</ul>
</h:column>
</h:dataTable>
所述<ui:repeat>
不里面工作<h:dataTable>
因為value
的的<ui:repeat>
使用所檢索的var
的的<h:dataTable>
。
對於一個不起眼的原因, <h:dataTable>
迭代正確的列表, 以及最后一次使用的所有對象null
值。 最后的迭代中斷了<ui:repeat>
。
解決方案是在獲取ui:repeat
value
的同時進行處理。 例如,如果您有類似的東西:
<h:dataTable value="#{someBean.parentObjList}" var="obj">
<h:column>
<ui:repeat value="#{someBean.getChildren(obj)" var="child" >
...
</ui:repeat>
</h:column>
</h:dataTable>
並在控制器中:
public List<ChildObj> getChildren(ParentObj obj) {
return parentObjService.findAllFor(obj);
}
然后,您需要將其替換為:
public List<ChildObj> getChildren(ParentObj obj) {
if (obj == null)
return new ArrayList<ChildObj>(); // return empty ArrayList to avoid crashing
else
return parentObjService.findAllFor(obj);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.