1 Reply Latest reply on May 15, 2013 10:00 AM by Alexey Shakov

    Controlling <rich:tree> selection from Java-Bean in RF4

    Alexey Shakov Newbie



      as i undestand, it can be reached using selection-attribute of <rich:tree>.


      can anybody provide an example of correct usage of it? (I use <rich:treeModelRecursiveAdaptor> to represent the model)


      Thanks in advance for any help,



        • 1. Re: Controlling <rich:tree> selection from Java-Bean in RF4
          Alexey Shakov Newbie

          I use the following code to test selection attribute:


          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          <html xmlns="http://www.w3.org/1999/xhtml" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich"
            xmlns:h="http://java.sun.com/jsf/html" xml:lang="en" lang="en">
            <a4j:log hotkey="M" mode="popup" />
              <rich:tree var="item"  selection="#{testBean.selection}">
                <rich:treeModelRecursiveAdaptor roots="#{testBean.roots}" nodes="#{item.children}">
                    <a4j:commandLink value="#{item.name}" />          
          public class TestBean {
              private Collection<?> selection;
              public Collection<?> getSelection() {
                  return selection;
              public void setSelection(Collection<?> selection) {
                  this.selection = selection;
              public List<Map<String, Object>> getRoots () {
                  List<Map<String, Object>> roots = new ArrayList<Map<String, Object>>();
                  Map<String, Object> n1 = new HashMap<String, Object>();
                  n1.put("name", "Node 1");
                  Map<String, Object> n1_1 = new HashMap<String, Object>();
                  n1_1.put("name", "Node 1_1");
                  List<Map<String, Object>> children = new ArrayList<Map<String, Object>>();
                  n1.put("children", children);
                  return roots;

          If link in tree is clicked, selection-property of TestBean is initialized with HashSet-instance and the instance of SequenceRowKey (i.e. [org.richfaces.model.SequenceRowKey[DeclarativeModelKey{modelId=j_id_8, modelKey=0}]] ) is put in it.


          So, if i want to manipulate the selection from java-bean side, i need to create my own instance of SequenceRowKey (corresponding to desired selection) and put it in this collection. To do this, I need component ids of tree nodes, so i must traverse UITree-component to find them. It is very inconvinient, in RF3 it was much simpler...


          We are migrating from RF3 to RF4 and tree selection issue is currently a big problem for us. Please help!