Search code examples
javajsf-2

h:dataTable inside ui:repeat, how specify render id from f:ajax?


I have:

<ui:repeat id="projectsTable" var="project" value="#{projectsBacking.projectList}">
  #{project.id}
  <h:dataTable id="usersAssignedToProject#{project.id}" var="appUser" value="#{projectsBacking.getAllUsersAssignedToProject(project)}">
    #{project.id}
    <h:column>
      <h:outputText value="#{appUser.getUsername()}"/>
    </h:column>
  </h:dataTable>
</ui:repeat>

Using <f:ajax> I can not render h:dataTable with given id, can someone explain me what is wrong in this code? When I checked by FireBug <table id="usersAssignedToProject">, but in client side #{project.id} was printed (before and inside datatable).


Solution

  • It is because of id of h:dataTable is resolved when components tree is being build, but var project is only available on render response. Try using c:forEach in this case instead of ui:repeat.

    More information on this: https://rogerkeays.com/jsf-c-foreach-vs-ui-repeat