4 Replies Latest reply on May 23, 2015 12:46 PM by Timo Hahn

    af:tree Navigation

    1006302

      Hi All,

       

      I am using jdeveloper 11.1.2.4

       

      I have created af:tree and given the link. When user click on any item, i am expecting to get all the value(record) related to the clicked item.

      Ex, when user click on Employee(ANUP as per below diagram), i should get all the details(EmpId, FirstName, Age, Salary etc) of the employee in side the bean.

       

      IT

         --Anup

         --Ashu

      HR

          --Ashok

          --Anu

       

       

      Any link or sample?

       

      Regards

        • 1. Re: af:tree Navigation
          Timo Hahn

          You create a tree (e.g. dempartment ->employee) and use this method as selection listener

          import java.util.Iterator;

          import java.util.List;

           

           

          import javax.el.ELContext;

          import javax.el.ExpressionFactory;

          import javax.el.MethodExpression;

           

           

          import javax.faces.application.Application;

          import javax.faces.context.FacesContext;

           

           

          import oracle.adf.model.BindingContext;

          import oracle.adf.model.binding.DCBindingContainer;

          import oracle.adf.model.binding.DCIteratorBinding;

          import oracle.adf.share.logging.ADFLogger;

          import oracle.adf.view.rich.component.rich.data.RichTree;

           

           

          import oracle.jbo.Row;

          import oracle.jbo.uicli.binding.JUCtrlHierBinding;

          import oracle.jbo.uicli.binding.JUCtrlHierNodeBinding;

           

           

          import org.apache.myfaces.trinidad.event.SelectionEvent;

          import org.apache.myfaces.trinidad.model.CollectionModel;

          import org.apache.myfaces.trinidad.model.RowKeySet;

          import org.apache.myfaces.trinidad.model.TreeModel;

           

           

           

           

          public class TreeSelectionBean {

              private static ADFLogger logger = ADFLogger.createADFLogger(TreeSelectionBean.class);

           

           

              public void onTreeNodeSelection(SelectionEvent selectionEvent) {

                  //original selection listener set by ADF

                  //#{bindings.DepartmentsView.treeModel.makeCurrent}

                  String adfSelectionListener = "#{bindings.DepartmentsView.treeModel.makeCurrent}";

                  //make sure the default selection listener functionality is

                  //preserved. you don't need to do this for multi select trees

                  //as the ADF binding only supports single current row selection

           

           

                  /* START PRESERVER DEFAULT ADF SELECT BEHAVIOR */

                  FacesContext fctx = FacesContext.getCurrentInstance();

                  Application application = fctx.getApplication();

                  ELContext elCtx = fctx.getELContext();

                  ExpressionFactory exprFactory = application.getExpressionFactory();

           

           

                  MethodExpression me = null;

                  me = exprFactory.createMethodExpression(elCtx, adfSelectionListener, Object.class, new Class[] { SelectionEvent.class });

                  me.invoke(elCtx, new Object[] { selectionEvent });

           

           

                  /* END PRESERVER DEFAULT ADF SELECT BEHAVIOR */

                  RichTree tree = (RichTree) selectionEvent.getSource();

                  TreeModel model = (TreeModel) tree.getValue();

           

           

                  //get selected nodes

                  RowKeySet rowKeySet = selectionEvent.getAddedSet();

                  Iterator rksIterator = rowKeySet.iterator();

                  //for single select configurations,this only is called once

                  while (rksIterator.hasNext()) {

                      List key = (List) rksIterator.next();

                      JUCtrlHierBinding treeBinding = null;

                      CollectionModel collectionModel = (CollectionModel) tree.getValue();

                      treeBinding = (JUCtrlHierBinding) collectionModel.getWrappedData();

                      JUCtrlHierNodeBinding nodeBinding = null;

                      nodeBinding = treeBinding.findNodeByKeyPath(key);

                      Row rw = nodeBinding.getRow();

                      //print first row attribute. Note that in a tree you have to

                      //determine the node type if you want to select node attributes

                      //by name and not index

                      String rowType = rw.getStructureDef().getDefName();

           

           

                      if (rowType.equalsIgnoreCase("DepartmentsView")) {

                          logger.info("This row is a department: " + rw.getAttribute("DepartmentId"));

                      } else if (rowType.equalsIgnoreCase("EmployeesView")) {

                          logger.info("This row is an employee: " + rw.getAttribute("EmployeeId"));

                          Object attribute = rw.getAttribute("EmployeeId");

                          // make the selected row the current row in the child iterator

                          DCBindingContainer dcBindings = (DCBindingContainer) BindingContext.getCurrent().getCurrentBindingsEntry();

                          DCIteratorBinding iterBind = (DCIteratorBinding) dcBindings.get("EmployeesOfDeepartmentViewIterator");

                          iterBind.setCurrentRowWithKeyValue(attribute.toString());

                      } else {

                          logger.info("Huh????");

                      }

                      // ... do more useful stuff here

                  }

              }

          }

          And in the page the tree and a form for the detail data looks like

                              <af:gridCell width="100%" halign="stretch" valign="stretch" id="gc2">

                                  <!-- Content -->

                                  <af:panelCollection id="pc1">

                                      <f:facet name="menus"/>

                                      <f:facet name="toolbar"/>

                                      <f:facet name="statusbar"/>

                                      <af:tree value="#{bindings.DepartmentsView.treeModel}" var="node" selectionListener="#{TreeSelectionBean.onTreeNodeSelection}"

                                               rowSelection="single" id="t1" editingMode="clickToEdit">

                                          <f:facet name="nodeStamp">

                                              <af:outputText value="#{node}" id="ot1"/>

                                          </f:facet>

                                      </af:tree>

                                  </af:panelCollection>

                                  <af:panelFormLayout id="pfl1" partialTriggers="pc1:t1 pc1:t1:ot1">

                                      <af:inputText value="#{bindings.EmployeeId.inputValue}" label="#{bindings.EmployeeId.hints.label}"

                                                    required="#{bindings.EmployeeId.hints.mandatory}" readOnly="true" columns="#{bindings.EmployeeId.hints.displayWidth}"

                                                    maximumLength="#{bindings.EmployeeId.hints.precision}" shortDesc="#{bindings.EmployeeId.hints.tooltip}" id="it1">

                                          <f:validator binding="#{bindings.EmployeeId.validator}"/>

                                          <af:convertNumber groupingUsed="false" pattern="#{bindings.EmployeeId.format}"/>

                                      </af:inputText>

                                      <af:inputText value="#{bindings.FirstName.inputValue}" label="#{bindings.FirstName.hints.label}"

                                                    required="#{bindings.FirstName.hints.mandatory}" readOnly="true" columns="#{bindings.FirstName.hints.displayWidth}"

                                                    maximumLength="#{bindings.FirstName.hints.precision}" shortDesc="#{bindings.FirstName.hints.tooltip}" id="it2">

                                          <f:validator binding="#{bindings.FirstName.validator}"/>

                                      </af:inputText>

                                      <af:inputText value="#{bindings.LastName.inputValue}" label="#{bindings.LastName.hints.label}"

                                                    required="#{bindings.LastName.hints.mandatory}" readOnly="true" columns="#{bindings.LastName.hints.displayWidth}"

                                                    maximumLength="#{bindings.LastName.hints.precision}" shortDesc="#{bindings.LastName.hints.tooltip}" id="it3">

                                          <f:validator binding="#{bindings.LastName.validator}"/>

                                      </af:inputText>

                                      <af:inputText value="#{bindings.Email.inputValue}" label="#{bindings.Email.hints.label}"

                                                    required="#{bindings.Email.hints.mandatory}" readOnly="true" columns="#{bindings.Email.hints.displayWidth}"

                                                    maximumLength="#{bindings.Email.hints.precision}" shortDesc="#{bindings.Email.hints.tooltip}" id="it4">

                                          <f:validator binding="#{bindings.Email.validator}"/>

                                      </af:inputText>

                                  </af:panelFormLayout>

                              </af:gridCell>

          The selection listener of the tree points to the bean method onTreeNodeSelection(...) which handles the selection of the node in the tree and the selecting of the employee row in the sub node (employee).

          You have to change the iterator names to the names you use in your app.

           

          Timo

          • 2. Re: af:tree Navigation
            1006302

            Thanks a lot TIMO,

             

            It works.

             

            Regards & Thanks

            • 3. Re: af:tree Navigation
              aJohny

              Then please close the thread by marking the correct answer.

              • 4. Re: af:tree Navigation
                Timo Hahn

                Just publiched a whole sample which is better documented for this use case at https://tompeez.wordpress.com/2015/05/23/masterdetail-using-aftree-for-master-and-afform-for-detail/

                 

                Timo