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

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

    alsha

      Hi,

       

      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,

       

      Alexey

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

          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"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          
          <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">
          <h:head></h:head>
          <h:body>
            <a4j:log hotkey="M" mode="popup" />
            <h:form>
              <rich:tree var="item"  selection="#{testBean.selection}">
                <rich:treeModelRecursiveAdaptor roots="#{testBean.roots}" nodes="#{item.children}">
                  <rich:treeNode>
                    <a4j:commandLink value="#{item.name}" />          
                  </rich:treeNode>
                </rich:treeModelRecursiveAdaptor>
              </rich:tree>
            </h:form>
          </h:body>
          </html>
          
          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>>();
                  children.add(n1_1);
                  n1.put("children", children);
          
                  roots.add(n1);
                  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!