在ui中重复JSF组件:重复

jko*_*kob 2 ajax jsf primefaces

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

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

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

javax.servlet.ServletException: Cannot find component with identifier "counterPanel" in view.
Run Code Online (Sandbox Code Playgroud)

谢谢,雅各布

Bal*_*usC 5

两种方式:

  1. 您需要提供<ui:repeat>客户端ID,以便可以通过绝对客户端ID路径引用它:

    <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>
    
    Run Code Online (Sandbox Code Playgroud)
  2. 移动<h:form>到外部循环内部,以便您可以使用@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>
    
    Run Code Online (Sandbox Code Playgroud)