ajax - 地址 ui 中的 JSF 组件 :repeat

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

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

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

谢谢, 雅各布

最佳答案

两种方式:

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

关于ajax - 地址 ui 中的 JSF 组件 :repeat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9700487/

相关文章:

HTML 5 下拉菜单和 JSF 2.2

ajax - 向 Ajax 事件监听器发送附加参数

jsf - primefaces 文件上传无效的文件类型 doc, docx

jsf - 无法让 PrimeFaces RequestContext.getCurrentInstance().openDialog() 工作

javascript - Primefaces 水印 : hide placeholder on click

jsf - 具有复合组件作为选项卡的 Primefaces TabView

php - 我可以在请求的 javascript 中访问我的 ajax 请求的 href 吗?

javascript - 如何确保 $scope.property 在使用之前具有值(value)

JavaScript:函数在没有 alert() 的情况下无法工作

php - 将 JSON 数据发送到 PHP 服务器(本地主机到托管站点)