1

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?

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
  • 1
    Does this answer your question? [How to find out client ID of component for ajax update/render? Cannot find component with expression "foo" referenced from "bar"](https://stackoverflow.com/questions/8634156/how-to-find-out-client-id-of-component-for-ajax-update-render-cannot-find-compo) – Jasper de Vries Jul 01 '22 at 07:56
  • Sadly not. My problem ocures before the page is even rendered. Also it can't be resolved by giving elements fixed id's because their id's are generated on go and trying to use something like `varStatus="status"` with usage in the element like `id="group_#{status.index}"` resulted in error. Different but still error. – Jan Dvořák Jul 01 '22 at 10:51
  • 1
    Either first remove the update or use the path from the exception. It's just a matter of using a chain of `@parent`s until you've reached the component containing the group card. – Jasper de Vries Jul 01 '22 at 10:55

0 Answers0