开发者

How to refer to dataTable parent within the dataTable?

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 开发者_如何学Cam wrapping the dataTable within a panelGroup as suggested here.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜