在 ui:repeat 中解决 JSF 组件 [英] Address JSF component in ui:repeat

查看:22
本文介绍了在 ui:repeat 中解决 JSF 组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更新 UI-repeat 中的元素,但不幸的是,我仍然没有发现如何从 dataTable 中正确处理 outputPanel.我知道这个问题来自不同的命名容器,但我希望有一个解决方案.

I'm trying to update an element within an UI-repeat, but unfortunately I still haven't discovered how to correctly address the outputPanel from within the dataTable. I am aware that this problem comes from the different naming containers, nevertheless, I hope there will be a solution.

<h:body>
    <h:form id="form">
        <ui:repeat var="_entry" value="#{test.entries}">
            <p:outputPanel id="counterPanel">
                <h:outputText value="#{test.counter}" />
            </p:outputPanel>

            <p:dataTable var="_p" id="paramTable" value="#{_entry.params}">
                <p:column headerText="Options">
                    <p:commandLink value="Update" update="counterPanel"  />
                </p:column>
            </p:dataTable>
        </ui:repeat>
    </h:form>
</h:body>

上面的代码示例引发了以下异常:

The code example above raises the following exception:

javax.servlet.ServletException: Cannot find component with identifier "counterPanel" in view.

谢谢,雅各布

推荐答案

两种方式:

  1. 您需要为 提供一个客户端 ID,以便您可以通过绝对客户端 ID 路径引用它:

  1. You need to give the <ui:repeat> a client ID so that you can refer it by the absolute client ID path:

<h:form id="form">
    <ui:repeat id="entries" var="_entry" value="#{test.entries}">
        <p:outputPanel id="counterPanel">
            <h:outputText value="#{test.counter}" />
        </p:outputPanel>

        <p:dataTable var="_p" id="paramTable" value="#{_entry.params}">
            <p:column headerText="Options">
                <p:commandLink value="Update" update=":form:entries:counterPanel" />
            </p:column>
        </p:dataTable>
    </ui:repeat>
</h:form>

  • 移到外循环内部,以便您可以使用 @form:

  • Move the <h:form> to inside the outer loop so that you can use @form:

    <ui:repeat var="_entry" value="#{test.entries}">
        <h:form id="form">
            <p:outputPanel id="counterPanel">
                <h:outputText value="#{test.counter}" />
            </p:outputPanel>
    
            <p:dataTable var="_p" id="paramTable" value="#{_entry.params}">
                <p:column headerText="Options">
                    <p:commandLink value="Update" update="@form" />
                </p:column>
            </p:dataTable>
        </h:form>
    </ui:repeat>
    

  • 这篇关于在 ui:repeat 中解决 JSF 组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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