2 Replies Latest reply on Jan 4, 2014 9:08 AM by 222222

    treeSelectionChangeListener didn’t work in richFaces 4.3.4 ?

    222222

      test.xhtml

      <rich:tree id="tree"

      value="#{stations.getStationNodes()}"

      var="node"

      selectionType="ajax"

      selectionChangeListener="#{stations.selectionChanged}">

      <rich:treeSelectionChangeListener listener="#{stations.selectionChanged}"/>

      </rich:tree>

      stations

      package stations;

      import java.io.Serializable;

      import java.util.ArrayList;

      import java.util.List;

      import javax.faces.bean.ManagedBean;

      import javax.faces.bean.RequestScoped;

      import javax.faces.bean.SessionScoped;

      import javax.faces.bean.ViewScoped;

      import javax.faces.event.AbortProcessingException;

      import org.richfaces.component.UITree;

      import org.richfaces.event.TreeSelectionChangeEvent;

      import org.richfaces.event.TreeSelectionChangeListener;

      import org.richfaces.model.TreeNode;

      import my_tree.OptionTreeNode;

       

      @ManagedBean(name = "stations")

      @SessionScoped 

      @ViewScoped

      public class Stations implements Serializable, TreeSelectionChangeListener{

          private static final long serialVersionUID = 1L;

       

          private OptionTreeNode stationRoot = new OptionTreeNode();

       

          private OptionTreeNode stationNodes = new OptionTreeNode();

         

          public OptionTreeNode getStationNodes() { 

              return stationNodes; 

          }

         

          public Stations()

          {

              h();

          }

       

          private String[] kickRadioFeed = {

              "Hall & Oates - Kiss On My List",

              "David Bowie - Let's Dance",

              "Lyn Collins - Think (About It)",

              "Kim Carnes - Bette Davis Eyes",

              "KC & the Sunshine Band - Give It Up" };

      public void h()

          {

          //stationRoot.addChild(key, child);

          stationRoot.setName("KickRadio");

          stationNodes.addChild(0, stationRoot);

          for (int i = 0; i < kickRadioFeed.length; i++)

          {

          OptionTreeNode child = new OptionTreeNode();

          child.setName(kickRadioFeed[i]);

          stationRoot.addChild(i, child);

          }

         

          }

          //----------------------------

          public void selectionChanged(TreeSelectionChangeEvent event)

          {

              //OptionTreeNode child = new OptionTreeNode();

              //child.setName("**-->");

              //stationRoot.addChild(0, child);

             

              UITree tree = (UITree)event.getSource();

              //System.out.println("**");

              List<Object> selection = new ArrayList<Object>(event.getNewSelection());

              Object currentSelectionKey = selection.get(0);

              OptionTreeNode child = (OptionTreeNode)currentSelectionKey;

              child.setName("**-->");

              //stationRoot.addChild(0, child);

              TreeNode currentSelection = (TreeNode) tree.getRowData();

              currentSelection.addChild(0, child);

             

          }

         

          public void onClick()

          {

              OptionTreeNode child = new OptionTreeNode();

              child.setName("**-->");

              //stationRoot.addChild(0, child);

          }

       

          @Override

          public void processTreeSelectionChange(TreeSelectionChangeEvent event)

                  throws AbortProcessingException {

              // TODO Auto-generated method stub

              System.out.println("change");

              OptionTreeNode child = new OptionTreeNode();

              child.setName("**-->");

          }

         

      }

      (JBoss EAP 6.1)

      not work

      help

        • 1. Re: treeSelectionChangeListener didn’t work in richFaces 4.3.4 ?
          lfryc

          Are you indicating that it worked before 4.3.4 (e.g. on 4.3.3 or 4.2.x) and that it doesn't work anymore?

           

          Could you provide some deubugging feedback?

          debugging-richfaces-issues.md

          1 of 1 people found this helpful
          • 2. Re: treeSelectionChangeListener didn’t work in richFaces 4.3.4 ?
            222222

            http://showcase.richfaces.org/richfaces/component-sample.jsf?demo=tree&skin=blueSky

            thank you Ilya Shaikovsky

             

             

            All well work

             

            there was so
            OptionTreeNode implements org.richfaces.model.TreeNode

            necessary

            OptionTreeNode implements javax.swing.tree.TreeNode;

             

             

             

                                                                                                        test.xhtml

            <h:form>
            <h:commandButton value="---------------------"/>
            <rich:tree id="tree2"  var="node0" nodeType="#{node0.type}" value="#{stations.stationRoots}"  toggleType="client"
            selectionType="ajax" render="tree2" selectionChangeListener="#{stations.selectionChanged}">
            <rich:treeNode type="node" iconExpanded="/images/tree/song.gif" iconCollapsed="/images/tree/disc.gif">
            <h:outputText value="#{node0.name}" title="#{node0.name}"/>
            </rich:treeNode>
            <rich:treeNode type="node2" iconExpanded="/images/tree/song.gif" iconCollapsed="/images/tree/disc.gif">
            222
            </rich:treeNode>
            </rich:tree>
            <h:commandButton value="---------------------"/>
            </h:form>

             

                                                                         OptionTreeNode.java

            package my_tree;

             

            import java.io.Serializable;

            import java.util.ArrayList;

            import java.util.Enumeration;

            import java.util.List;

            import javax.faces.bean.ManagedBean;

            import javax.faces.bean.SessionScoped;

            import javax.faces.bean.ViewScoped;

             

             

            import javax.swing.tree.TreeNode;

             

             

            import com.google.common.collect.Iterators;

            @ManagedBean(name = "my_node")

            @SessionScoped 

            @ViewScoped

            public class OptionTreeNode  implements Serializable,TreeNode{

             

                private static final long serialVersionUID = 1L;

                public String name; 

                public String type;

                private TreeNode parent;

                private List<TreeNode> child  = new ArrayList<TreeNode>();

                public OptionTreeNode(String name,TreeNode parent)

                {

                    this.name=name;

                    this.type="node";

                    this.parent=parent;

                }

                public OptionTreeNode()

                {

                    type="node";

                    this.name="nam*";

                }

                 

                public String getName() {

                    System.out.println("getName() "+this);

                    return this.name; 

                } 

             

                public void setName(String name) {

                    System.out.println("setName() "+name+" "+this);

                    this.name = name; 

                } 

               /* @Override

                public String toString() { 

                    return this.name; 

                }*/

             

                public String getType() {

                    return type;

                }

             

                public void setType(String type) {

                    this.type = type;

                }

             

                @Override

                public Enumeration children() {

                    // TODO Auto-generated method stub

                    return Iterators.asEnumeration(child.iterator());

                }

             

                @Override

                public boolean getAllowsChildren() {

                    // TODO Auto-generated method stub

                    return true;

                }

             

                @Override

                public TreeNode getChildAt(int arg0) {

                    // TODO Auto-generated method stub

                    return  child.get(arg0);

                }

             

                @Override

                public int getChildCount() {

                    // TODO Auto-generated method stub

                    return child.size();

                }

             

                @Override

                public int getIndex(TreeNode arg0) {

                    // TODO Auto-generated method stub

                    return child.indexOf(arg0);

                }

             

                @Override

                public TreeNode getParent() {

                    // TODO Auto-generated method stub

                    return parent;

                }

             

                @Override

                public boolean isLeaf() {

                    // TODO Auto-generated method stub

                    return false;

                }

             

                public void addChild(OptionTreeNode child2) {

                    // TODO Auto-generated method stub

                     child.add(child2);

                }

             

               

            }

             

             

                                                                                                            Stations.java

            ManagedBean(name = "stations")

             

            @SessionScoped 

            @ViewScoped

            public class Stations implements Serializable, TreeSelectionChangeListener,

            ActionListener{

             

                @Resource(mappedName="java:/my_connect")

                private javax.sql.DataSource ds00;

                               

                public javax.sql.DataSource getDs00() {

                    return ds00;

                }

             

                private static final long serialVersionUID = 1L;

             

                public List<OptionTreeNode> stationRoots=null;

                public OptionTreeNode stationRoot= null;

                private TreeNode currentSelection = null;

                

                public List<OptionTreeNode> getStationRoots() {

                    return stationRoots;

                }

             

                public void setStationRoots(List<OptionTreeNode> stationRoots) {

                    this.stationRoots = stationRoots;

                }

                           

                public OptionTreeNode getStationRoot() {

                    return stationRoot;

                }

             

                public void setStationRoot(OptionTreeNode stationRoot) {

                    this.stationRoot = stationRoot;

                }

             

                public Stations()

                {

                   

                }

             

                private String[] kickRadioFeed = {

                    "Hall & Oates - Kiss On My List",

                    "David Bowie - Let's Dance",

                    "Lyn Collins - Think (About It)",

                    "Kim Carnes - Bette Davis Eyes",

                    "KC & the Sunshine Band - Give It Up" };

             

                   

                @PostConstruct

                public void h()

                {

                stationRoot = new OptionTreeNode("**",null);

                stationRoot.setName("KickRadio");

                this.stationRoots=new ArrayList<OptionTreeNode>();

                this.stationRoots.add(stationRoot);

             

                for (int i = 0; i < kickRadioFeed.length; i++)

                {

                OptionTreeNode child = new OptionTreeNode(kickRadioFeed[i],stationRoot);

                child.setName(kickRadioFeed[i]);

                stationRoot.addChild( child);

                }

               

                }

                //----------------------------

                public void selectionChanged(TreeSelectionChangeEvent selectionChangeEvent)

                {

                    System.out.println("selectionChanged");

                    List<Object> selection = new ArrayList<Object>(selectionChangeEvent.getNewSelection());

                    Object currentSelectionKey = selection.get(0);

                    UITree tree = (UITree) selectionChangeEvent.getSource();

             

                    Object storedKey = tree.getRowKey();

                    tree.setRowKey(currentSelectionKey);

                    currentSelection = (TreeNode) tree.getRowData();

                    tree.setRowKey(storedKey);

                    ((OptionTreeNode)currentSelection).addChild(new OptionTreeNode("child",currentSelection));

                    sss=  ((OptionTreeNode)currentSelection).getName();

                }

               

            *

            *

            *   

            }