ui:repeat in o:treeNodeItem

140 views Asked by At

I have an <o:tree> where i am displaying list of persons and each person what it has children and every child what it have children where the level of children is not known
The data is displayed correctly but the displayed node is an <h:commandLink> where its action is a java bean function

Snippet of java code :

public class PersonController{
   //class Person having List of children
   //some code
   public void readChild(double childId){
   }
   //some code
}

Snippet of jsf code :

<o:tree>
   <o:treeNodeItem>
      <ui:repeat var="person" value="#{personController.person}">
         #{person.id}
         <ui:repeat var="child" value="#{person.children}">
            <h:commandLink value="#{child.id}" action="#{personController.readChild(child.id)}"/>
         </ui:repeat>
      </ui:repeat>
   </o:treeNodeItem>
</o:tree>

Rendered page :

--person : 1
----child : 1.1
----child : 1.2
--person : 2
----child : 2.1
----child : 2.2

The main problem is that #{personController.readChild(child.id)} id child 1.1 is clicked the parameted double childId is sent 2.2 where any child is clicked the last parameter is sent where in case all values are displayed correctly

1

There are 1 answers

0
bob-cac On BEST ANSWER

I send a paramater f:param instead of the parameter send by the function

In this way the id is send properly by every node

Snippet of java code :

public class PersonController{
   //class Person having List of children
   //some code

   //remove parameter double childId
   public void readChild(){
      // getting parameter
      Map<String,String> params = 
                FacesContext.getExternalContext().getRequestParameterMap();
      String id = Double.parseDouble(params.get("id"));
   }
   //some code
}

Snippet of jsf code :

<o:tree>
   <o:treeNodeItem>
      <ui:repeat var="person" value="#{personController.person}">
         #{person.id}
         <ui:repeat var="child" value="#{person.children}">
            <h:commandLink value="#{child.id}" action="#{personController.readChild()}">
               <f:param name="id" value="#{child.id}"/>
            </h:commandLink>
         </ui:repeat>
      </ui:repeat>
   </o:treeNodeItem>
</o:tree>