ui:repeat in o:treeNodeItem

北战南征 提交于 2019-12-12 04:34:10

问题


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:


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>


来源:https://stackoverflow.com/questions/26911704/uirepeat-in-otreenodeitem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!