<f:ajax> contains an unknown id :someid when used in <ui:repeat>
My code snippet:
<ui:repeat var="o">
<h:panelGroup id="someid">
<ui:repeat>
// HTML
</ui:repeat>
</h:panelGroup>
<div>
<h:form>
<h:commandButton action="#{o.doSomething}">
开发者_StackOverflow <f:ajax event="action" render=":someid" />
</h:commandButton>
<h:form>
</div>
</ui:repeat>
Why didn't <f:ajax>
find someid
?
That's not possible. The <ui:repeat>
prepends the client ID with its own ID and an index. All those panelgroups get IDs like j_id1:0:someid
, j_id1:1:someid
, j_id1:2:someid
, etc. The following is supposed to work in your particular construct:
<f:ajax render=":#{component.parent.parent.clientId}:someid" />
This will prepend the <ui:repeat>
's current client ID dynamically. It however only works when you're using with MyFaces instead of Mojarra. The <ui:repeat>
is broken in many ways in Mojarra. They have scheduled many fixes for 2.2.
An alternative is to group them in a common NamingContainer
component like <h:form>
, so that you can use a relative ID.
<ui:repeat var="o">
<h:form>
<h:panelGroup id="someid">
<ui:repeat>
// HTML
</ui:repeat>
</h:panelGroup>
<div>
<h:commandButton action="#{o.doSomething}">
<f:ajax event="action" render="someid" />
</h:commandButton>
</div>
<h:form>
</ui:repeat>
精彩评论