0 Replies Latest reply on Aug 23, 2011 5:46 AM by Oussema Ouss

    Problem with tree in richfaces 3.3 final

    Oussema Ouss Newbie

      Hi everybody,i really need help,i cant deal with my tree and get data from it,i had an exception:

      javax.servlet.ServletException: java.lang.IllegalStateException: No tree element available or row key not set!

      i know the cause of the exception but i didnt find any explan so the solution;in fact when i debbug it crash in the preparecreateGarantie method,

      the cant get object from the tree uiTree

      here the code where it crash:

       

       

       

      public String prepareCreateGarantie() {

              // System.out.println("DossierNodeType:"+dossierNode.getType());

              // FIXME find parent node

              DossierNode parent = (DossierNode) uiTree.getTreeNode().getParent()

                      .getData();

       

              IServiceCreanceElementaire sce = (IServiceCreanceElementaire) FacesContext

                      .getCurrentInstance()

                      .getApplication()

                      .getELResolver()

                      .getValue(FacesContext.getCurrentInstance().getELContext(),

                              null, "serviceCreanceElementaire");

       

              CreanceElementaire ce = (CreanceElementaire) sce.find(Integer

                      .valueOf(parent.getId()));

       

       

              GarantieController garantieController = (GarantieController) FacesContext

                      .getCurrentInstance()

                      .getApplication()

                      .getELResolver()

                      .getValue(FacesContext.getCurrentInstance().getELContext(),

                              null, "garantieController");

       

              garantieController.prepareCreate(ce);

              return null;

          }

       

      //********************///////

       

       

      here my code JSF:

       

       

      <rich:tree binding="#{dossierController.uiTree}"   nodeSelectListener="#{dossierController.processSelection}"

                              reRender="selectedNode" ajaxSubmitSelection="true"  switchType="client"

                              value="#{dossierController.treeNode}" var="item" ajaxKeys="#{null}" nodeFace="#{item.type}"

                              selectedClass="treeClassSelected"

                              rowKeyVar="rowKey">

       

                              <rich:treeNode nodeClass="#{item.selected?'treeClassSelected':''}" type="creance" icon="/images/icons/dossier/creance.png" iconExpanded="/images/icons/dossier/creance.png" iconLeaf="/images/icons/dossier/creance.png" iconCollapsed="/images/icons/dossier/creance.png">

                                  <ui:include src="/xhtmlFile/dossier/treeTitle.xhtml"/>

                              </rich:treeNode>

       

                              <rich:treeNode nodeClass="#{item.selected?'treeClassSelected':''}" type="chronologie" icon="/images/icons/dossier/chronologie.png" iconLeaf="/images/icons/dossier/chronologie.png">

                                  <ui:include src="/xhtmlFile/dossier/treeTitle.xhtml"/>

                              </rich:treeNode>

       

                              <rich:treeNode nodeClass="#{item.selected?'treeClassSelected':''}" type="relation" icon="/images/icons/dossier/relation.png" iconExpanded="/images/icons/dossier/relation.png" iconLeaf="/images/icons/dossier/relation.png" iconCollapsed="/images/icons/dossier/relation.png">

                                  <ui:include src="/xhtmlFile/dossier/treeTitle.xhtml"/>

                              </rich:treeNode>

       

                              <rich:treeNode nodeClass="#{item.selected?'treeClassSelected':''}" type="contrat" icon="/images/icons/dossier/contrat.png">

                                  <ui:include src="/xhtmlFile/dossier/treeTitle.xhtml"/>

                              </rich:treeNode>

                              <rich:treeNode nodeClass="#{item.selected?'treeClassSelected':''}" type="jugement" icon="/images/icons/dossier/jugement.png">

                                  <ui:include src="/xhtmlFile/dossier/treeTitle.xhtml"/>

                              </rich:treeNode>

                              <rich:treeNode nodeClass="#{item.selected?'treeClassSelected':''}" type="operation" icon="/images/icons/dossier/operation.png">

                                  <ui:include src="/xhtmlFile/dossier/treeTitle.xhtml"/>

                              </rich:treeNode>

                              <rich:treeNode nodeClass="#{item.selected?'treeClassSelected':''}" type="garantieEtat" icon="/images/icons/dossier/garantie_etat1.png">

                                  <ui:include src="/xhtmlFile/dossier/treeTitle.xhtml"/>

                              </rich:treeNode>

                              <rich:treeNode nodeClass="#{item.selected?'treeClassSelected':''}" type="garantieReelle" icon="/images/icons/dossier/garantie.png">

                                  <ui:include src="/xhtmlFile/dossier/treeTitle.xhtml"/>

                              </rich:treeNode>

                              <rich:treeNode nodeClass="#{item.selected?'treeClassSelected':''}" type="prestation" icon="/images/icons/dossier/prestation.png" iconLeaf="/images/icons/dossier/prestation.png">

                                  <ui:include src="/xhtmlFile/dossier/treeTitle.xhtml"/>

       

                              </rich:treeNode>

                              <rich:treeNode nodeClass="#{item.selected?'treeClassSelected':''}" type="caution" icon="/images/icons/dossier/caution.png" iconLeaf="/images/icons/dossier/caution.png">

                                  <ui:include src="/xhtmlFile/dossier/treeTitle.xhtml"/>

                              </rich:treeNode>

                              <rich:treeNode nodeClass="#{item.selected?'treeClassSelected':''}" type="restructuration" icon="/images/icons/dossier/restructuration.png" iconLeaf="/images/icons/dossier/restructuration.png">

                                  <ui:include src="/xhtmlFile/dossier/treeTitle.xhtml"/>

                              </rich:treeNode>

       

       

       

                               <rich:treeNode id="listOperationRecouvrementNode" nodeClass="#{item.selected?'treeClassSelected':''}" type="listOperationRecouvrement">

                                  <ui:include src="/xhtmlFile/dossier/treeTitle.xhtml"/>

                                  <rich:contextMenu event="oncontextmenu" attachTo="listOperationRecouvrementNode" submitMode="none">

                                      <rich:menuItem value="#{msgs2.action_add} opération de recouvrement" onclick="#{rich:component('mpAddPrestation')}.show()"/>

                                  </rich:contextMenu>

                              </rich:treeNode>

       

                              <rich:treeNode nodeClass="#{item.selected?'treeClassSelected':''}" type="dossier">

                                  <ui:include src="/xhtmlFile/dossier/treeTitle.xhtml"/>

                              </rich:treeNode>

       

                              <rich:treeNode id="listJugementNode" nodeClass="#{item.selected?'treeClassSelected':''}"  type="listJugement">

                                  <ui:include src="/xhtmlFile/dossier/treeTitle.xhtml"/>

                                  <rich:contextMenu event="oncontextmenu" attachTo="listJugementNode" submitMode="ajax" >

                                      <rich:menuItem ajaxSingle="true" value="#{msgs2.action_add} Jugement" onclick="#{rich:component('mpAddJugement')}.show()" action="#{dossierController.prepareCreateJugement}" reRender="addJugementGroup"/>

                                  </rich:contextMenu>

                              </rich:treeNode>

       

       

       

                              <rich:treeNode id="listPrestationNode" nodeClass="#{item.selected?'treeClassSelected':''}" type="listPrestations">

                                  <ui:include src="/xhtmlFile/dossier/treeTitle.xhtml"/>

                                  <rich:contextMenu event="oncontextmenu"  attachTo="listPrestationNode"  submitMode="ajax">

                                      <rich:menuItem ajaxSingle="true" value="#{msgs2.action_add} prestation" onclick="#{rich:component('mpAddPrestation')}.show()" action="#{dossierController.prepareCreateMission}" reRender="addJugementGroup"/>

                                  </rich:contextMenu>

                              </rich:treeNode>

       

                              <rich:treeNode id="listOperationNode" nodeClass="#{item.selected?'treeClassSelected':''}" type="listOperation">

                                  <ui:include src="/xhtmlFile/dossier/treeTitle.xhtml"/>

                                  <rich:contextMenu event="oncontextmenu"  attachTo="listOperationNode" submitMode="ajax">

                                      <rich:menuItem  ajaxSingle="true"  value="#{msgs2.action_add} Operation"  onclick="#{rich:component('mpAddOperation')}.show()" action="#{creanceElementaireController.prepareCreateOperation}"  reRender="addOperationGroup">

                                      </rich:menuItem>

                                  </rich:contextMenu>

                              </rich:treeNode>

       

                              <!-- FIXME add contrat -->

                              <rich:treeNode id="listContratNode" nodeClass="#{item.selected?'treeClassSelected':''}" type="listContrat">

                                  <ui:include src="/xhtmlFile/dossier/treeTitle.xhtml"/>

                                  <rich:contextMenu event="oncontextmenu"  attachTo="listContratNode"  submitMode="ajax">

                                      <rich:menuItem  ajaxSingle="true"  value="#{msgs2.action_add} Operation"  onclick="#{rich:component('mpAddContrat')}.show()" action="#{creanceElementaireController.prepareCreateContrat}"  reRender="addContratGroup"/>

                                  </rich:contextMenu>

                              </rich:treeNode>

       

                              <rich:treeNode id="listCautionNode" nodeClass="#{item.selected?'treeClassSelected':''}" type="listCautions">

                                  <ui:include src="/xhtmlFile/dossier/treeTitle.xhtml"/>

                                  <rich:contextMenu event="oncontextmenu" attachTo="listCautionNode" submitMode="ajax" >

                                      <rich:menuItem  value="#{msgs2.action_add} caution" onclick="#{rich:component('mpAddCaution')}.show()" action="#{dossierController.prepareCreateGarantie}" reRender="addCautionGroup"/>

                                  </rich:contextMenu>

                              </rich:treeNode>

       

                               <rich:treeNode id="listGarantieReelleNode" nodeClass="#{item.selected?'treeClassSelected':''}" type="listGarantieReelles">

                                  <ui:include src="/xhtmlFile/dossier/treeTitle.xhtml"/>

                                  <rich:contextMenu event="oncontextmenu" attachTo="listGarantieReelleNode" submitMode="ajax">

                                      <rich:menuItem  value="#{msgs2.action_add} garantie réelle" onclick="#{rich:component('mpAddGarantieReelle')}.show()" action="#{dossierController.prepareCreateGarantie}" reRender="addGarantieReelleGroup"/>

                                  </rich:contextMenu>

                              </rich:treeNode>

       

                              <rich:treeNode id="listGarantieEtatNode" nodeClass="#{item.selected?'treeClassSelected':''}" type="listGarantieEtats">

                                  <ui:include src="/xhtmlFile/dossier/treeTitle.xhtml"/>

                                  <rich:contextMenu event="oncontextmenu" attachTo="listGarantieEtatNode" submitMode="ajax">

                                      <rich:menuItem  value="#{msgs2.action_add} garantie de l'état" onclick="#{rich:component('mpAddGarantieEtat')}.show()" action="#{dossierController.prepareCreateGarantie}" reRender="addGarantieEtatGroup"/>

                                  </rich:contextMenu>

                              </rich:treeNode>

       

       

                          </rich:tree>

       

      my code java :

       

       

      public void load tree ()

      {

       

       

              // (re)load all data

       

              rootNode = new TreeNodeImpl<DossierNode>();

              // allNodes=new HashSet<TreeNode<DossierNode>>();

              allNodes = new ArrayList<TreeNode<DossierNode>>();

       

              rootNode.setData(new DossierNode("", "root", ""));

              allNodes.add(rootNode);

       

              // Dossier

              // TreeNodeImpl dossierNode = new TreeNodeImpl<DossierNode>();

              // dossierNode.setData(new

              // DossierNode("Dossier","dossier","8784548754"));

              // rootNode.addChild(new Integer(1), dossierNode);

              int counter = 1;

              // allNodes.add(dossierNode);

       

              // créance

              TreeNodeImpl creanceNode = new TreeNodeImpl<DossierNode>();

              DossierNode dn = new DossierNode("Créance", "creance", "878454");

              creanceNode.setData(dn);

              // if(dossierNode==null)dn.setSelected(true);

              rootNode.addChild(new Integer(counter), creanceNode);

              counter++;

              allNodes.add(creanceNode);

       

              // restructuration

              /*

               * TreeNodeImpl restructurationNode = new TreeNodeImpl<DossierNode>();

               * restructurationNode.setData(new

               * DossierNode("Restructuration","restructuration","95658"));

               * dossierNode.addChild(new Integer(counter), restructurationNode);

               * counter++; allNodes.add(restructurationNode);

               */

       

              // chronologie

             

                TreeNodeImpl chronologieNode = new TreeNodeImpl<DossierNode>();

                chronologieNode.setData(new

                DossierNode("Chronologie","chronologie","9853215"));

                rootNode.addChild(new Integer(counter), chronologieNode); counter++;

                allNodes.add(chronologieNode);

              

       

              // relation

       

              TreeNodeImpl relationNode = new TreeNodeImpl<DossierNode>();

              relationNode.setData(new DossierNode("Relation", "relation", "5895665"));

              rootNode.addChild(new Integer(counter), relationNode);

              counter++;

              allNodes.add(relationNode);

       

              /*

               * //opérations de recouvrements TreeNodeImpl

               * listOperationRecouvrementNode = new TreeNodeImpl<DossierNode>();

               * listOperationRecouvrementNode.setData(new

               * DossierNode("Opérations de recouvrements"

               * ,"listOperationRecouvrement","")); rootNode.addChild(new

               * Integer(counter), listOperationRecouvrementNode); counter++;

               * addOperationRecouvrement(listOperationRecouvrementNode);

               * allNodes.add(listOperationRecouvrementNode);

               */

       

              // Liste des jugements

             

              /*  TreeNodeImpl listJugementNode = new TreeNodeImpl<DossierNode>();

                listJugementNode.setData(new

                DossierNode("Jugements","listJugement","878454"));

                rootNode.addChild(new Integer(counter), listJugementNode);

                addJugements(listJugementNode); counter++;

                allNodes.add(listJugementNode);*/

             

       

              // Liste des contrats

       

              TreeNodeImpl listContratNode = new TreeNodeImpl<DossierNode>();

              listContratNode.setData(new DossierNode("Contrats", "listContrat","878454"));

              rootNode.addChild(new Integer(counter), listContratNode);

              addContrats(listContratNode);

              counter++;

              allNodes.add(listContratNode);

       

              // Liste des opérations

       

              TreeNodeImpl listOperationNode = new TreeNodeImpl<DossierNode>();

              listOperationNode.setData(new DossierNode("Opérations",

                      "listOperation", "878454"));

              rootNode.addChild(new Integer(counter), listOperationNode);

              addOperations(listOperationNode);

              counter++;

              allNodes.add(listOperationNode);

       

      }

       

       

      ///****************************************************************///

       

      public void processselection(NodeSelectedEvent event)

      {

       

       

              // TODO Working copy

       

              HtmlTree tree = (HtmlTree) event.getComponent();

              previousSelectedDossierNode = dossierNode;

              dossierNode = (DossierNode) tree.getRowData();

              dossierNode.setSelected(true);

              // XXX nodeTitle = dossierNode.getTitle();

              // System.out.println("Original selected state:"+((DossierNode)

              // tree.getRowData()).isSelected());

              if (previousSelectedDossierNode != null) {

                  // double select problem

                  if (previousSelectedDossierNode != dossierNode) {

                      previousSelectedDossierNode.setSelected(false);

                  }

              }

             

             if (dossierNode.type.equals("listGarantieReelles")) {

                 System.out.println("processSelection---dossierNode.type.equals(listGarantieReelles)");

                 if(creanceIdentifiant != null)

                 {

                  prepareViewGarantieReelleList();

                 }

              }

             if (dossierNode.type.equals("listCautions")) {

                 System.out.println("processSelection---dossierNode.type.equals(listCautions)");

                  //prepareViewGarantiePersonnelleList();

              }

             if (dossierNode.type.equals("listGarantieEtats")) {

                 System.out.println("processSelection---dossierNode.type.equals(listGarantieEtats)");

                 if(creanceIdentifiant != null)

                 {

                  prepareViewGarantieDEtatList();

                 }

              }

            

             if (dossierNode.type.equals("listJugement")) {

                    System.out.println("processSelection---dossierNode.type.equals(listJugement)");

                    if(creanceIdentifiant != null)

                   {

                    prepareViewJugementList();

                   }

               }

               

                if (dossierNode.type.equals("listPrestations")) {

                    System.out.println("processSelection---dossierNode.type.equals(listPrestations)");

                   // prepareViewPrestationsList();

               }

                if (dossierNode.type.equals("listContrat")) {

                      System.out.println("openNode---dossierNode.type.equals(listContrat)");

                   

                 }

               if (dossierNode.type.equals("listOperation")) {

                     System.out.println("openNode---dossierNode.type.equals(listOperation)");

                }

              

              if (dossierNode.type.equals("contrat")) {

                   System.out.println("processSelection---dossierNode.type.equals(contrat)");

                   creanceIdentifiant=Integer.valueOf(dossierNode.id);

                  prepareViewContrat(Integer.valueOf(dossierNode.id));

              } else

                 

                  if (dossierNode.type.equals("garantieReelle")

                      || dossierNode.type.equals("garantieEtat")

                      || dossierNode.type.equals("caution")) {

         

                 

                  if (dossierNode.type.equals("garantieEtat"))

                  {

                        System.out.println("processSelection---dossierNode.type.equals(garantieEtat)");

                      //  prepareViewPrestationsListForParent();

                        prepareViewGarantieDEtat(Integer.valueOf(dossierNode.id));

                 

                  }

                  if (dossierNode.type.equals("caution"))

                  {

                       System.out.println("processSelection---dossierNode.type.equals(caution)");

                 

                       prepareViewGarantie(Integer.valueOf(dossierNode.id));

                 

                  }

                  if (dossierNode.type.equals("garantieReelle"))

                  {

                      System.out.println("processSelection---dossierNode.type.equals(garantieReelle)");

                      //prepareViewPrestationsListForParent();

                      prepareViewGarantie(Integer.valueOf(dossierNode.id));

                 

                  }

                 

                 

                 

                 

                 

              } else if (dossierNode.type.equals("operation")) {

                 

                  prepareViewOperation(Integer.valueOf(dossierNode.id));

              } else if (dossierNode.type.equals("relation")) {

                  prepareViewRelation(Integer.valueOf(getCurrentRelation().getIdentifiant()));

              }

             

              else if (dossierNode.type.equals("jugement")) {

                  //prepareViewPrestationsListForParent();

                   prepareViewJugement(Integer.valueOf(dossierNode.id));

                  }

              else if (dossierNode.type.equals("prestation")) {

                   prepareViewMission(Integer.valueOf(dossierNode.id));

                  }

       

       

              // XXX

              /*

               * HtmlTree tree = (HtmlTree)event.getComponent(); Object rowKey =

               * tree.getRowKey(); TreeNode selectedNode =

               * tree.getModelTreeNode(rowKey); selectedNodes.put(rowKey,

               * selectedNode); for (Object curRowKey : selectedNodes.keySet()) {

               * System.out.println("Selected node : " +

               * selectedNodes.get(curRowKey).getData()); }

               */

       

              /*

               * clear this: liveDemo selectedNodeChildren.clear(); TreeNode

               * currentNode = tree.getModelTreeNode(tree.getRowKey()); if

               * (currentNode.isLeaf()){

               * selectedNodeChildren.add((String)currentNode.getData()); }else {

               * Iterator<Map.Entry<Object, TreeNode>> it = currentNode.getChildren();

               * while (it!=null &&it.hasNext()) { Map.Entry<Object, TreeNode> entry =

               * it.next();

               * selectedNodeChildren.add(entry.getValue().getData().toString()); } }

               */

      }

       

       

      i hope that you help me and thank you anyway