简体   繁体   English

解决ui:repeat中的JSF组件

[英]Address JSF component in ui:repeat

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. 我正在尝试更新UI重复中的元素,但是不幸的是,我仍然没有发现如何从dataTable中正确寻址outputPanel。 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.

Thx, Jakob 雅各布·Thx

Two ways: 两种方式:

  1. You need to give the <ui:repeat> a client ID so that you can refer it by the absolute client ID path: 您需要给<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. Move the <h:form> to inside the outer loop so that you can use @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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM