I use omnifaces o: tree from "branches", where each branch has a "list of leaves" with the attribute "color", which should be editable in the tree.
- branch 0 - leaf 0 (color = "green") - leaf 1 (color = "yellow") - branch 1 - leaf 0 (color = "purple") - branch 1_0 - leaf 1 (color = "red") - leaf 2 (color = "orange") - leaf 3 (color = "brown")
Adding / removing branches and adding leaves to any branch work fine and as expected. Also rendering any complex tree, including the entire list of leaves (displaying a color attribute with the correct value), works like a charme.
But changing the color or deleting the sheet (so that everything inside ui:repeat ) only works as expected for the last processed branch.
The color input fields for other sheets / branches do not work at all, and the link to delete a sheet in ui:repeat also does not work the same way as for a sheet attribute in removeLeaf (...) always gets the corresponding sheet from the last processed branch. Thus, in the above example, clicking delete for the yellow sheet from branch 0 will cause removeLeaf ( orange , branch 0), which then will not explicitly delete anything, since branch 0 does not have an orange sheet.
This is the code attached to the main part - if necessary, any other can be provided:
<h:form> <o:tree value="#{treeBean.tree}" var="branchEntity" varNode="branchNode"> <o:treeNode> <o:treeNodeItem> <ui:repeat value="#{branchEntity.leafList}" var="leaf"> <h:panelGrid columns="2"> <p:inputText value="#{leaf.color}" /> <p:commandLink action="#{treeBean.removeLeaf(leaf, branchEntity)}" styleClass="ui-icon ui-icon-trash" process="@form" update="@form" /> </h:panelGrid> </ui:repeat> <p:commandLink action="#{treeBean.addLeaf(branchEntity)}" styleClass="ui-icon ui-icon-plus" process="@form" update="@form" /> <o:treeInsertChildren /> </o:treeNodeItem> </o:treeNode> </o:tree> <p:commandButton id="save" value="Save" action="#{treeBean.save}" process="@form" update="@form" /> </h:form>
I know there is some problem with nested ui:repeat , but since I'm on Mojarra 2.1.19, I think this is not the case here. And actually nesting two ui:repeats works fine if I replace o:tree with ui:repeat , which iterates over a list of branches. But then I obviously lost the tree functionality I needed. I just checked this to verify that the nested ui:repeat working correctly.
This problem seems to be similar to another question , but it is not quite the same ...
If I replaced the internal ui:repeat with p:dataList (as suggested in some other answers to solving ui:repeat problems, and also now in BalusC's answer), removeLeaf () links will work fine, but still the input fields of the last branch color will be connected.
UPDATE: Now I had a closer look when using p:dataList . The POST content from the AJAX request I received from the browser developer tools looks good:
javax.faces.partial.ajax=true javax.faces.source=hForm:save javax.faces.partial.execute=hForm javax.faces.partial.render=hForm hForm:save=hForm:save hForm=hForm hForm:oTree:0:pDataList:0:color=green hForm:oTree:0:pDataList:1:color=yellow hForm:oTree:1:pDataList:0:color=purple hForm:oTree:1_0:pDataList:0:color=red hForm:oTree:1_0:pDataList:1:color=orange hForm:oTree:1_0:pDataList:2:color=brown javax.faces.ViewState=-6137230173999059936:-6718691551411872927
The treeBean.save () method simply writes the entire Tree.toString () command to the console, which ends as follows:
[Branch [leafList=[Leaf [color=null], Leaf [color=null]]], Branch [leafList=[Leaf [color=null]]] [Branch [leafList=[Leaf [color=red], Leaf [color=orange], Leaf [color=brown]]]]]
If the color had some kind of value! = Null before, the value remains unchanged - so it does not get the redundant value using null. I'm still not deep enough in the JSF to really know how to research where information gets lost along the way.
(I originally used Mojarra 2.1.19 on JBoss EAP 6.2 + Primefaces 5.2 + Omnifaces 2.1, but also looked the same way on Mojarra 2.2.12, TomEE, Primefaces 5.3 + Omnifaces 2.2. You can find the full Maven Eclipse project here. I added another a simple String attribute (no list) directly in Branch, which works fine.)