考虑一个虚拟案例:
<h:form id="wrapperForm">
<h:panelGroup id="rowsContainer">
<h:dataTable id="rowsTable" value="#{bean.rows}" var="row" >
<h:column>
<h:commandButton value="Click me to update (#{component.parent.parent.parent.clientId})">
<f:ajax render=":#{component.parent.parent.parent.clientId}" />
</h:commandButton>
</h:column>
</h:dataTable>
</h:panelGroup>
</h:form>
单击按钮时,id=rowsContainer
已成功更新。
但是,如果我添加ui:repeat
在那里,它不再起作用了:
<h:form id="wrapperForm">
<ui:repeat id="blocksRepeat" var="block" value="#{bean.blocks}">
<h:panelGroup id="rowsWrapper">
<h:dataTable id="rowsTable" value="#{block.rows}" var="row" >
<h:column>
<h:commandButton value="Click me 2 update (#{component.parent.parent.parent.clientId})">
<f:ajax render=":#{component.parent.parent.parent.clientId}" />
</h:commandButton>
</h:column>
</h:dataTable>
</h:panelGroup>
</ui:repeat>
</h:form>
相反,这得到:
<f:ajax> contains an unknown id ':wrapperForm:blocksRepeat:0:rowsWrapper' - cannot locate it in the context of the component j_idt363
然而,该组件确实具有该 ID,因此 EL 应该没问题。不知何故ui:repeat
破案。它是否可能尝试在实际循环之前评估 EL?
您如何参考rowsWrapper
数据表中的元素?
注:我最近问过ui:repeat 中奇怪的数据表命名, which 原来是一个错误。但是,这个问题不应该与此相关,因为我按照建议将 dataTable 包装在 panelGroup 中here.
实际上有两件事出了问题:
1) ui:repeat 被破坏
正如 BalusC 在问题评论中的回答,第一个问题(再次)发生是由于Mojarra 中的一个错误。它似乎ui:repeat
甚至包装容器都破损了h:dataTable
没有帮助。欲了解更多详情,请参阅问题“为什么 ui:repeat 中的 h:dataTable 没有获得正确的 ID?”以及这个问题的评论。
正如 BalusC 所建议的,解决方法是使用 h:dataTable 而不是ui:repeat
。它将提供不方便(<table>
) HTML 但有效。这消除了在内部迭代中添加和删除行时的一些奇怪问题。
注:一些问题ui:repeat
似乎在 Mojarra 2.0.3 中已修复,但并非全部。
2)参考文献失败了
即使h:dataTable
解决方法,参考内部h:dataTable
从里面的按钮失败。由于没有ui:repeat
在使用中,这一定是数据表内部的问题。我目前没有看到任何解决方案,所以我也针对这种行为提交了罚单.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)