我正在尝试更新 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.
谢谢, 雅各布
最佳答案
两种方式:
您需要提供
<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>
移动
<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/