如何在dataTable中引用dataTable父级?

Tuu*_*nen 5 java jsf jsf-2

考虑一个虚拟案例:

<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>
Run Code Online (Sandbox Code Playgroud)

单击按钮,id=rowsContainer可以按原样成功更新.

但是,如果我在ui:repeat那里添加它,它就不再起作用了:

<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>
Run Code Online (Sandbox Code Playgroud)

相反,这得到:

<f:ajax> contains an unknown id ':wrapperForm:blocksRepeat:0:rowsWrapper' - cannot locate it in the context of the component j_idt363
Run Code Online (Sandbox Code Playgroud)

但是,该组件确实存在该ID,因此EL应该没问题.不知何故ui:repeat打破了这种情况.是否可能在实际循环之前尝试评估EL?

你如何引用rowsWrapperdataTable中的元素?

注意:我最近在ui:repeat中询问了奇怪的dataTable命名,结果证明是一个错误.但是,这个问题与此无关,因为我将dataTable包装在panelGroup中,如此处所示.

Tuu*_*nen 3

实际上有两件事出了问题:

1) ui:repeat 被破坏

正如 BalusC 在问题评论中的回答,第一个问题(再次)由于Mojarra 中的错误而发生。它看起来ui:repeat是如此破碎,即使是容纳它的包装容器也h:dataTable无济于事。有关更多详细信息,请参阅问题“ Why does not h:dataTable inside ui:repeat get Correct ID? ”以及该问题的评论。

正如 BalusC 所建议的,解决方法是使用 h:dataTable 而不是ui:repeat。它将提供不方便的 ( <table>) HTML,但可以工作。这消除了在内部迭代中添加和删除行时的一些奇怪问题。

注意:一些问题ui:repeat似乎在 Mojarra 2.0.3 中得到了修复,但并非全部。

2)参考文献失败了

即使使用h:dataTable解决方法,从其内部的按钮对内部的引用h:dataTable也会失败。由于没有ui:repeat使用,这一定是数据表的内部问题。我目前没有看到任何解决方案,因此我也针对此行为提交了一张罚单