如何在dataTable中引用dataTable父级? [英] How to refer to dataTable parent within the dataTable?

查看:192
本文介绍了如何在dataTable中引用dataTable父级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑假案例:

<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>

点击按钮, id = rowsContainer 得到了成功的更新。

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

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

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>

相反,这得到:

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

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

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?

如何引用 rowsWrapper 元素来自在dataTable中?

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

注意:我最近询问过在ui:repeat内的奇数dataTable命名结果证明是一个错误。但是,这个问题与此无关,因为我按照建议将dataTable包装在panelGroup中这里

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.

推荐答案

实际上有两件事情出错:

There are actually two things going wrong:

1)ui:重复被打破

正如BalusC在评论中所回答的那样问题是,由于 Mojarra中的一个错误,第一个问题再次出现(再一次) 。似乎 ui:repeat 即使包含 h:dataTable 的包装容器也无法解决。有关详细信息,请参阅问题为什么hi中没有h:dataTable :重复获取正确的ID?以及此问题的评论。

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.

正如BalusC建议的那样,解决方法是使用h:dataTable而不是 UI:重复。它将提供不方便的(< table> )HTML但有效。这会在向内部迭代添加行或从内部迭代中删除行时消除一些奇怪的问题。

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.

注意:关于 ui:repeat 似乎在Mojarra 2.0.3中修复,但不是全部。

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

2)引用失败

即使使用 h:dataTable 解决方法,对内部 h的引用:dataTable 从里面的按钮失败。由于没有使用 ui:repeat ,这必须是数据表的内部问题。我目前没有看到任何解决方案,所以我为此行为提交了一张票

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.

这篇关于如何在dataTable中引用dataTable父级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆