我的页面由几个区域组成,这些区域是通过使用 <ui:repeat>
迭代项目列表而创建的。 .想象一下这个简化的例子:
<h:form id="form">
<ui:repeat id="repeatContainer" var="item" value="#{testBean.items}" varStatus="status">
<h:outputText value="#{item.title}: "/>
<!-- I want to re-render only a single one of these fields -->
<h:outputText id="valueContainer" value="#{item.value}"/><br/>
</ui:repeat>
</h:form>
现在,我想重新渲染(仅)
valueContainer
的 特定元素 在此列表中 使用 AJAX (例如,索引为 1 的元素)。我已经尝试了所有这些组合,但没有任何运气:<!-- Works, but renders all items: -->
<f:ajax render=":form"/>
<!-- This is what I actually want to achieve (does not work, comp. not found): -->
<f:ajax render=":form:repeatContainer:1:valueContainer"/>
<!-- Does not work (component not found): -->
<f:ajax render=":form:repeatContainer"/>
<!-- Does not work (component not found): -->
<f:ajax render=":form:repeatContainer:1"/>
<!-- Does not work (component not found): -->
<f:ajax render=":form:1"/>
<!-- Does not work (component not found): -->
<f:ajax render=":form:1:valueContainer"/>
<!-- Does not work (no error message, but does nothing): -->
<f:ajax render=":form:repeatContainer:valueContainer"/>
我的要求包括:
使用 重新渲染绝对标识符
路径 ,因为按钮
触发更新在某处
在组件上完全不同
树。
表单(使用
@all
/@form
)是对我没用,因为那种
质疑我为什么使用 JSF/AJAX
根本...
<p:dataGrid>
实现同样的目标单元格(即仅更新特定单元格的特定子组件),但我认为这会减少到相同的问题。 我想必须有一个简单的解决方案,我目前正在忽视这个问题?!
最佳答案
这似乎是由 Mojarra 2.0.2 中的两个单独的错误引起的。以下线程讨论了一个相关问题:
How to refer to dataTable parent within the dataTable?
就我而言,我使用的是 PrimeFaces <p:dataGrid>
而不是 <h:dataTable>
,但它似乎患有相同的症状。引用只是失败。我想这与 UIComponent#findComponent()
中的错误有关或 JSF 实现的底层方法。
看起来目前这个问题没有解决方案......除了等待 JSF 实现被修复......如果其他人有进一步的建议,请随时添加它们。
关于ajax - JSF 2.0 : Re-rendering/updating a single item in ui:repeat using AJAX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4660130/