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

时间:2022-11-21 20:09:50

My page consists of several areas which are created by iterating over a list of items using <ui:repeat>. Imagine this simplified example:

我的页面包含几个区域,这些区域是通过使用 迭代项目列表而创建的。想象一下这个简化的例子: :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>

Now, I want to re-render (only) the valueContainer of a specific element within this list using AJAX (say, the element with index 1). I have already tried all of these combinations without any luck:

现在,我想使用AJAX(例如,索引为1的元素)重新渲染(仅)此列表中特定元素的valueContainer。我已经尝试过所有这些组合而没有任何运气:

<!-- 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 / @形式)对我来说毫无用处,因为这样会让我对使用JSF / AJAX的原因产生疑问......
  • I need to achieve the same thing with PrimeFaces <p:dataGrid> cells (i.e. update only a specific sub-component of a specific cell), but I assume that this reduces to the same problem.
  • 我需要使用PrimeFaces

    单元格来实现相同的功能(即仅更新特定单元格的特定子组件),但我认为这会减少到同样的问题。

    :datagrid>

I guess there must be an easy solution to this that I am currently overlooking?!

我想一定有一个简单的解决方案,我目前正在俯瞰?!

2 个解决方案

#1


0  

It seems that this is caused by two separate bugs in Mojarra 2.0.2. The following thread discusses a related issue: How to refer to dataTable parent within the dataTable?

这似乎是由Mojarra 2.0.2中的两个独立错误引起的。以下主题讨论了一个相关问题:如何在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. The references just fail. I suppose this is related to a bug in UIComponent#findComponent() or the underlying methods of the JSF implementation.

在我的情况下,我使用PrimeFaces

而不是 ,但它似乎遭受相同的症状。引用失败了。我想这与UIComponent#findComponent()中的错误或JSF实现的基础方法有关。 :datatable>

:datagrid>

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实现...如果其他人有进一步的建议,请随时添加它们。

#2


0  

The problem can be solved by placing the form in a prime faces p:outputPanel and set the autoUpdate to true

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

#1


0  

It seems that this is caused by two separate bugs in Mojarra 2.0.2. The following thread discusses a related issue: How to refer to dataTable parent within the dataTable?

这似乎是由Mojarra 2.0.2中的两个独立错误引起的。以下主题讨论了一个相关问题:如何在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. The references just fail. I suppose this is related to a bug in UIComponent#findComponent() or the underlying methods of the JSF implementation.

在我的情况下,我使用PrimeFaces

而不是 ,但它似乎遭受相同的症状。引用失败了。我想这与UIComponent#findComponent()中的错误或JSF实现的基础方法有关。 :datatable>

:datagrid>

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实现...如果其他人有进一步的建议,请随时添加它们。

#2


0  

The problem can be solved by placing the form in a prime faces p:outputPanel and set the autoUpdate to true

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