地址JSF组件的UI:重复组件、地址、JSF、UI

2023-09-10 16:58:37 作者:女生唯美阳光安静

我想更新UI重复中的一个元素,但不幸的是我还没有发现如何正确地从数据表中解决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>

在code上面的例子引发以下异常:

The code example above raises the following exception:

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

THX, 雅各布

Thx, Jakob

推荐答案

有两种方式:

您需要给&LT; UI:重复&GT; 客户端ID,这样你可以在绝对的客户端ID路径是指它:

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>

移动&LT; H:形式GT; 外循环中,使您可以使用 @form

值得推荐的Blazor UI组件库

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>