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>
. 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). 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 fou开发者_如何学Gond): -->
<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... - 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.
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. The following thread discusses a related issue: How to refer to dataTable parent within the 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.
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.
The problem can be solved by placing the form in a prime faces p:outputPanel and set the autoUpdate to true
精彩评论