5

Consider a dummy case:

<h:form id="wrapperForm">
    <h:panelGroup id="rowsContainer">
        <h:dataTable id="rowsTable" value="#{bean.rows}" var="row" >
            <h:column>
                <h:commandButton value="Click me to update (#{component.parent.parent.parent.clientId})">
                    <f:ajax render=":#{component.parent.parent.parent.clientId}" />
                </h:commandButton>
            </h:column>
        </h:dataTable>
    </h:panelGroup>
</h:form>

On button click, the id=rowsContainer gets successfully updated as it should.

However, if I add ui:repeat there, it does not work anymore:

<h:form id="wrapperForm">
    <ui:repeat id="blocksRepeat" var="block" value="#{bean.blocks}">
        <h:panelGroup id="rowsWrapper">
            <h:dataTable id="rowsTable" value="#{block.rows}" var="row" >
                <h:column>
                    <h:commandButton value="Click me 2 update (#{component.parent.parent.parent.clientId})">
                        <f:ajax render=":#{component.parent.parent.parent.clientId}" />
                    </h:commandButton>
                </h:column>
            </h:dataTable>
        </h:panelGroup>
    </ui:repeat>
</h:form>

Instead, this gets:

<f:ajax> contains an unknown id ':wrapperForm:blocksRepeat:0:rowsWrapper' - cannot locate it in the context of the component j_idt363

However, that component is really there with that ID, so the EL should be ok. Somehow the ui:repeat breaks the case. Is it possibly trying to evaluate the EL before the actual loop?

How do you refer to the rowsWrapper element from within the dataTable?

Note: I recently asked about odd dataTable naming within ui:repeat, which turned out to be a bug. This issue should not be related to that, however, as I am wrapping the dataTable within a panelGroup as suggested here.

Community
  • 1
  • 1
Tuukka Mustonen
  • 4,722
  • 9
  • 49
  • 79
  • `ui:repeat` again ~sic. It would be nice if the JSF guys introduced a fullworthy `UIData` component which is similar to good ol' Tomahawk's `t:dataList` which allows output markup control as `
      `, `
      ` or nothing.
    – BalusC Oct 07 '10 at 14:56
  • But in this case the clientIDs that the dataTables get, really are unique. Also, I don't even try to refer directly to the dataTables here, but to their panelGroup wrappers (so the reference should not cause an issue). I would have thought that makes a difference, but guess it still causes some issues then? – Tuukka Mustonen Oct 07 '10 at 19:48
  • No, the problem is that `ui:repeat` isn't a fullworthy `UIData` component and behaves differently as oppsed to e.g. `HtmlDataTable`. If you replace `ui:repeat` by `h:dataTable` it will work (but the final HTML is is ugly, yes). – BalusC Oct 08 '10 at 13:26
  • You are right, I had a similar case when replacing the `ui:repeat` with `h:dataTable` really solved the situation (believe it does so in this case as well). However, in some cases simply updating to Mojarra 2.0.3 helped, I actually opened up a question that should summarize the whole hassle around ui:repeat (not to duplicate information but to help other desperate souls find the cause when in the same situation). See http://stackoverflow.com/questions/3890862/jsf-mojarra-2-0-2-uirepeat-is-totally-broken-when-updating-via-ajax/3890890 It seems they fixed at least something for Mojarra 2.0.3 – Tuukka Mustonen Oct 08 '10 at 13:43

1 Answers1

3

There are actually two things going wrong:

1) ui:repeat is broken

As answered by BalusC in the comments of the question, the first issue occurs (once again) due to a bug in Mojarra. It seems ui:repeat is so broken even the wrapper container holding the h:dataTable does not help. For more details, see question "Why doesn't h:dataTable inside ui:repeat get correct ID?" and the comments of this question.

As BalusC suggests, a workaround is to use h:dataTable instead of ui:repeat. It will provide unconvenient (<table>) HTML but works. This removes some odd issues when adding and removing rows to/from the inner iteration.

Note: some issues regarding ui:repeat seem to be fixed in Mojarra 2.0.3 but not all.

2) The references just fail

Even with h:dataTable workaround, the reference to the inner h:dataTable from the button inside it fails. As there is no ui:repeat in use, this must be datatable's internal issue. I don't see any solution at the moment, so I filed a ticket for this behavior as well.

Community
  • 1
  • 1
Tuukka Mustonen
  • 4,722
  • 9
  • 49
  • 79