1 Reply Latest reply on Jan 7, 2014 2:30 PM by Edilmar Alves

    Is it possible to select more than one node of a rich:tree (4.3.4)?

    Edilmar Alves Expert



      I tried to select more nodes but it didn't work, then full tree was selected after select the first node.

        • 1. Re: Is it possible to select more than one node of a rich:tree (4.3.4)?
          Edilmar Alves Expert

          I made a mix of two 4.x showcase samples (rich:tree and treeAdaptors) because I need to import a XML file to the tree. Then, I used the rich:treeModelRecursiveAdaptor to fill recursively the tree. All works fine. But I also need to allow the user to select one or more fields from the generated XML tree, and to this, I used the rich:tree record music sample. Now, I get to select one, and just one group field from XML, but:

          1) I didn't get to select many fields, just the original problem of this message

          2) I didn't get to call the selectionChangeListener method for leaves of the tree (final field contents)


          Here is a sample JSF/RF code:



              <rich:tree id="campos" var="item"



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

                <rich:treeModelRecursiveAdaptor roots="#{emissaoCCe.raizArqXMLAss}" nodes="#{item.grupos}">

                  <rich:treeNode expanded="true">

                    <h:outputText value="#{item.tituloGrupo}"/>


                  <rich:treeModelAdaptor nodes="#{item.campos}">


                      <h:outputText value="#{item.tituloCampo}"/>







            <a4j:outputPanel ajaxRendered="true" layout="block">

              <rich:panel header="Current Selection">

                <h:outputText value="Name:" />

                <h:outputText value="#{emissaoCCe.s}" />




          The bean:




          public class EmissaoCCeController extends GenericCadController<ConhecimentoEv> implements Serializable {

            @Inject ConhecimentoEvDAO daoI;


            private EmissaoCCeCampos currentSelection = null;

            public EmissaoCCeCampos getCurrentSelection() {

              return currentSelection;



            public void setCurrentSelection(EmissaoCCeCampos currentSelection) {

              this.currentSelection = currentSelection;



            public void selectionChanged(TreeSelectionChangeEvent selectionChangeEvent) {

              try {

                // considering only single selection

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

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

                Object storedKey = tree.getRowKey();


                Object currentSelectionKey = selection.get(0);


                currentSelection = (EmissaoCCeCampos) tree.getRowData();

                if (currentSelection.isCampo())

                  s = currentSelection.getTituloCampo(); // THIS DOESNT WORK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


                  s = currentSelection.getTituloGrupo();



              } catch (Exception e) {





            private String s;


            public String getS() {

              return s;



            public void setS(String s) {

              this.s = s;




          And the class of nodes:

          public class EmissaoCCeCampos {

            private Node node;

            private List<EmissaoCCeCampos> grupos;

            private List<EmissaoCCeCampos> campos;

            private String tituloCampo;

            public EmissaoCCeCampos(Node node) {

              this.node = node;

              grupos = null;

              campos = null;

              this.tituloCampo = null;


            public EmissaoCCeCampos(String tituloCampo) {

              this.node = null;

              grupos = null;

              campos = null;

              this.tituloCampo = tituloCampo;


            public String getTituloGrupo() {

              return node.getNodeName();


            public String getTituloCampo() {

              return tituloCampo;


            public synchronized List<EmissaoCCeCampos> getGrupos() {

              if (grupos == null) {

                NodeList nodeList = node.getChildNodes();

                int len = nodeList.getLength();

                grupos = new ArrayList<>();

                campos = new ArrayList<>();

                int i;

                for (i = 0; i < len; i++) {

                  Node nodeAtual = nodeList.item(i);

                  if (nodeAtual.getNodeName().equals("Signature")) {



                  NodeList childrenNodeAtual = nodeAtual.getChildNodes();

                  int lenAtual = childrenNodeAtual.getLength();

                  if (lenAtual == 1 && childrenNodeAtual.item(0).getNodeName().equals("#text")) {

                    Node childNodeAtual = childrenNodeAtual.item(0);

                    campos.add(new EmissaoCCeCampos(nodeAtual.getNodeName() + "=" + childNodeAtual.getNodeValue()));



                    grupos.add(new EmissaoCCeCampos(nodeAtual));



              return grupos;


            public synchronized List<EmissaoCCeCampos> getCampos() {

              return campos;


            public boolean isGrupo() {

              return tituloCampo == null;


            public boolean isCampo() {

              return tituloCampo != null;