简体   繁体   English

JSF 2.0:在ui中重新渲染/更新单个项目:使用AJAX重复

[英]JSF 2.0: Re-rendering/updating a single item in ui:repeat using AJAX

My page consists of several areas which are created by iterating over a list of items using <ui:repeat> . 我的页面由几个区域组成,这些区域是通过使用<ui:repeat>迭代项目列表而创建的。 Imagine this simplified example: 想象一下这个简化的例子:

<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>

Now, I want to re-render (only) the valueContainer of a specific element within this list using AJAX (say, the element with index 1). 现在,我想使用AJAX (例如,索引为1的元素)重新渲染(仅)此列表中特定元素valueContainer I have already tried all of these combinations without any luck: 我已经尝试过所有这些组合而没有任何运气:

<!-- 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"/>

My requirements include: 我的要求包括:

  • I need to identify the component to re-render with an absolute identifier path , because the button that triggers the update is somewhere completely different in the component tree. 我需要使用绝对标识符路径来标识要重新呈现的组件,因为触发更新的按钮在组件树中完全不同。
  • Re-rendering the entire page or form (using @all / @form ) is useless to me, because that kind of puts into question why I am using JSF/AJAX at all... 重新渲染整个页面或表单(使用@all / @form )对我来说毫无用处,因为这样会让我对使用JSF / AJAX的原因产生疑问......
  • I need to achieve the same thing with PrimeFaces <p:dataGrid> cells (ie update only a specific sub-component of a specific cell), but I assume that this reduces to the same problem. 我需要使用PrimeFaces <p:dataGrid>单元格来实现相同的功能(即仅更新特定单元格的特定子组件),但我认为这会减少到同样的问题。

I guess there must be an easy solution to this that I am currently overlooking?! 我想我必须有一个简单的解决方案,我目前正在俯瞰?!

It seems that this is caused by two separate bugs in Mojarra 2.0.2. 这似乎是由Mojarra 2.0.2中的两个独立错误引起的。 The following thread discusses a related issue: How to refer to dataTable parent within the dataTable? 以下主题讨论了一个相关问题: 如何在dataTable中引用dataTable父级?

In my case, I am using the PrimeFaces <p:dataGrid> instead of <h:dataTable> , but it seems to suffer from the same symptoms. 在我的情况下,我使用PrimeFaces <p:dataGrid>而不是<h:dataTable> ,但它似乎遭受相同的症状。 The references just fail. 引用失败了。 I suppose this is related to a bug in UIComponent#findComponent() or the underlying methods of the JSF implementation. 我想这与UIComponent#findComponent()的错误或JSF实现的基础方法有关。

Looks like there is no solution to this problem at the moment... except for waiting for the JSF implementations to be fixed... if someone else has further suggestions, feel free to add them. 看起来目前还没有这个问题的解决方案...除了等待修复JSF实现...如果其他人有进一步的建议,请随时添加它们。

可以通过将表单放在主面p:outputPanel中并将autoUpdate设置为true来解决此问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM