JSF-重复更新重复元素

发布于 2025-02-12 01:19:28 字数 1959 浏览 1 评论 0原文

我有一个有点奇怪的代码,但它是这样的:

<h:form id="groupsForm">
  <ui:repeat value="#{groupsContainer.groups}" var="group">
    <p:outptuText value="#{group.name}" />
    <p:card id="group">
      <ui:repeat value="#{group.users}" var="user">
        <p:outputText value="#{user.name}" />
        <p:commandButton
            value="Delete"
            process="@this"
            actionListener="#{groupsController.deleteUserFromGroup(group, user)}"
            update="group"
        />
      </ui:repeat>
    </p:card>
  </ui:repeat>
</h:form>

可悲的是,命令按钮在呈现页面以Java错误结尾时找不到该组的组:

org.primefaces.expression.componentnotfoundException:找不到从“ groupsForm:j_idt42:0:j_idt73:0:j_idt102”中引用的“ group”的组件。

我无法从其中的另一个重复重复引用重复的组件。我尝试使用ID并将某些组件包装在&lt; H:PanelGroup/&gt;中,但这没有帮助。

然后,我意识到我不需要更新整个&lt; p:card/&gt;,并且仅能更新第二个&lt; ui:repot/&gt; < /code>,所以我这样做了:

<h:form id="groupsForm">
  <ui:repeat value="#{groupsContainer.groups}" var="group">
    <p:outptuText value="#{group.name}" />
    <p:card id="group">
      <h:panelGroup id="users">
        <ui:repeat value="#{group.users}" var="user">
          <p:outputText value="#{user.name}" />
          <p:commandButton
              value="Delete"
              process="@this"
              actionListener="#{groupsController.deleteUserFromGroup(group, user)}"
              update="users"
          />
        </ui:repeat>
      </h:panelGroup>
    </p:card>
  </ui:repeat>
</h:form>

但是结果仅与不同的ID相同:

找不到从“ groupsform:j_idt42:0:j_idt73:0:j_idt102”的表达式“用户”的组件。

所以我的问题是:我可以以某种方式更新重复组件,然后重复第二次重复?

I have a code that is little bit odd but it goes something like this:

<h:form id="groupsForm">
  <ui:repeat value="#{groupsContainer.groups}" var="group">
    <p:outptuText value="#{group.name}" />
    <p:card id="group">
      <ui:repeat value="#{group.users}" var="user">
        <p:outputText value="#{user.name}" />
        <p:commandButton
            value="Delete"
            process="@this"
            actionListener="#{groupsController.deleteUserFromGroup(group, user)}"
            update="group"
        />
      </ui:repeat>
    </p:card>
  </ui:repeat>
</h:form>

Sadly that command button can't find the group in which it is when rendering the page ending with Java error:

org.primefaces.expression.ComponentNotFoundException: Cannot find component for expression "group" referenced from "groupsForm:j_idt42:0:j_idt73:0:j_idt102".

It seams to me that you can't reference a repeated component from another repeat that is in it. I tried to play with the ids and wrap some components in <h:panelGroup/> but that didn't helped.

Then I realised that I don't need to update the whole <p:card/> and it should be enough to update only the second <ui:repeat/>, so I did this:

<h:form id="groupsForm">
  <ui:repeat value="#{groupsContainer.groups}" var="group">
    <p:outptuText value="#{group.name}" />
    <p:card id="group">
      <h:panelGroup id="users">
        <ui:repeat value="#{group.users}" var="user">
          <p:outputText value="#{user.name}" />
          <p:commandButton
              value="Delete"
              process="@this"
              actionListener="#{groupsController.deleteUserFromGroup(group, user)}"
              update="users"
          />
        </ui:repeat>
      </h:panelGroup>
    </p:card>
  </ui:repeat>
</h:form>

but the result was pretty much the same with only different ids:

Cannot find component for expression "users" referenced from "groupsForm:j_idt42:0:j_idt73:0:j_idt102".

So my question is: Can I somehow update repeated component with repeat from inside of the second repeat?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文