Liam Donovan
Liam Donovan

Reputation: 11

How can I add a treeNode into each iteration of a ui:repeat

I have an object DetailsTO which contains TreeNode treeNode, TreeNode[] selectedNodes, and InnerDetailsTO innerDetails

I have a list of these DetailsTO, each of which contains it's own treeNode and selectedNodes. There could be several DetailsTO in the list at any given time. I am displaying this list of these detailsTOs on screen which will allow the user to check/uncheck any combination of nodes for each of the TreeNodes. The user then presses a save button which maps the selections to each of the associated InnerDetailsTOs.

My issue is when I click save, the application only has values for the last selectedNodes in the list and seems to have lost all knowledge of any of the selectedNodes related to the detailsTO from previous entries within the dataList. So, if I select a few checkboxes from different TreeNodes and then save and reopen the screen, only the last treeNode has any values. The rest are all blank.

I have tried this with a ui:repeat also and am getting the same results.

Is there a way to iterate through this list of TreeNodes, but keep an individual selectedNodes[] for each iteration?

<p:dataList type="none" value="#{BackingBean.detailsTO}" var="detailsTO">
    <div class="panel mb-3 d-flex flex-column">
        <div class="panel-header d-flex justify-content-between">
            <div>#{detailsTO.name}</div>
        </div>
        <p:tree value="#{detailsTO.treeNode}" var="item" selectionMode="checkbox" selection="#{detailsTO.selectedNodes}">
            <p:treeNode type="type-apple">
                <h:outputText value="#{item.name}" />
            </p:treeNode>
            <p:treeNode type="type-orange">
                <h:outputText value="#{item.otherName}" />
            </p:treeNode>
        </p:tree>
    </div>
</p:dataList>

Upvotes: 1

Views: 42

Answers (0)

Related Questions