Skip to Content
avatar image
Former Member

Easy Question on tree - The text is not getting displayed

Hi Experts,

I have created one WD program. It fetches data from R/3 using RFC. I have created Tree UI element in the view. I have added "TreeNodeType" inside the "tree" ui element. I have done context mapping of "tree" and "TreeNodeType" with the RFC ouput.

I have also created a Table to see the RFC output

For a particular set of input RFC fetches 4 records. I can see 4 records in Table. The Tree element also shows a structure with 4 branches.

I want the branches of tree to display the 4 records. For example if the 4 output of RFC are pernr 1, 2, 3, 4 then Tree branch should also display 1,2 ,3 , 4

How I can do so? I have already gone through following PDF. But it is not helping.

Populating a Tree with Inputs from an RFC Model.PDF

Regards,

Gary

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • Best Answer
    avatar image
    Former Member
    Jul 04, 2009 at 02:30 PM

    Gary,

    Well, you will have to assign an action to the "onLoadChildren" event of the TreeNodeType and implement code for that action.

    You also need a recursive node in the context and you can use that to load children.

    Here is a tutorial that should help you:

    https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/f0ec6622-8da5-2a10-349b-868b6a553efa?overridelayout=true

    Instead of loading the children from the java class you will use your BAPI.

    Hope this helps.

    Regards,

    Motaz

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi,

      Thanks. The program is working fine. One last request - how I can use the RFC instead of Java class. I have written the execute BAPI code in controller. How the data of controller can be used in wdDoInit of view. The existing code is

      public void wdDoInit()
      { //@@begin wdDoInit()
      //=== STEP 1: Load all initial Data from Filesystem.properties ====
      resourceHandlerForTree =
      WDResourceHandler.createResourceHandlerForCurrentSession();
      // Load the resource bundle "Filesystem.properties" located
      // in the package "com.sap.tut.wd.tree.resources"
      // for locale set in the resource handler.
      resourceHandlerForTree.loadResourceBundle(
      "resources.Filesystem",
      this.getClass().getClassLoader());
      // get all Drives
      String drives = resourceHandlerForTree.getString("Drives");
      StringTokenizer strTokenizer = new StringTokenizer(drives, ";");
      //=== STEP 2: Create node elements of the typ IFolderContentNode ==
      IPrivateTreeView.IFolderContentNode rootFolderContentNode =
      wdContext.nodeFolderContent();
      IPrivateTreeView.IFolderContentElement rootFolderContentElement;
      // begin populating context node 'FolderContent'
      String aDriveToken;
      while (strTokenizer.hasMoreTokens()) {
      aDriveToken = strTokenizer.nextToken();
      // instantiate the new context node element of type
      // 'IFolderContentElement'
      rootFolderContentElement =
      rootFolderContentNode.createFolderContentElement();
      //set contained context value attributes
      rootFolderContentElement.setText(aDriveToken);
      rootFolderContentElement.setHasChildren(true);
      rootFolderContentElement.setIconSource(
      "~sapicons/s_clofol.gif");
      rootFolderContentElement.setIgnoreAction(true);
      // add root folder element to root folder node
      rootFolderContentNode.addElement(rootFolderContentElement);
      // if last folder node element, fill its non-singleton
      // child node (storing its entries) with children (folder node
      // elements) and expand the node ('Drive D' in tree).
      if (!strTokenizer.hasMoreTokens()) {
      addChildren(rootFolderContentElement);
      rootFolderContentElement.setIsExpanded(true);
      } else {
      rootFolderContentElement.setIsExpanded(false);
      }
      }
      //@@end

      How I can modify the code.

      Regards,

      Gary

  • avatar image
    Former Member
    Jul 05, 2009 at 11:13 AM

    Gary,

    To populate the tree you need to do that using code. You need to context nodes from the root. One is the RFC output node and the other is a node containing all attributes of the RFC output node plus a recursive node (call it Node1). Node1 along with the attributes are created manually and the attributes have the same types as their corresponding RFC attributes. You also create a recursive node inside Node1 that refers to Node1.

    Now in the "onLoadChildren" action you create a new element of the recursive node and set its attributes to the attributes of the RFC node for that level. You can create more than one element for all RFC elements in that level. Here is a sample code to initialize the tree:

    IPrivateTreeTree2.INavigationNode INNN=wdContext.nodeNavigation();

    IPrivateTreeTree2.INavigationElement INE;

    IPrivateTreeTree2.INavigationNodeElement INNE;

    for(int i=0; i<wdContext.nodeNavigationNode().size();i++)

    {

    INE=wdContext.nodeNavigation().createAndAddNavigationElement();

    INNE=(IPrivateTreeTree2.INavigationNodeElement)wdContext.nodeNavigationNode().getElementAt(i);

    INE.setRole(INNE.getTitle());

    INE.setURI(INNE.getNodeURI());

    if(INNE.getHasChildren())

    INE.setIsLeaf(true);

    else

    INE.setIsLeaf(false);

    }

    INNN is my Node1. INE is an element instance of Node1. INNE is an element instance of the RFC node.

    As you see, I refer to the context and get the elements in the RFC node then set the attributes of INE to corresponding attributes of INNE. (Role and Title are the same attribute. The name change is for convenience).

    Hope this helps.

    Regards,

    Motaz

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 04, 2009 at 01:57 PM

    Hello Gary,

    Did you bind the "text" property of the "TreeNodeType" to the attribute of the context you want to display?

    Regards,

    Motaz

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Motaz,

      I have set the property 'datasource' of 'treetypenode' to 'Hrwpc_Rfc_Oadp_Get_Navobjects_Input.Output_Hrwpc.T_Navobjects'.

      'Hrwpc_Rfc_Oadp_Get_Navobjects_Input.Output_Hrwpc.T_Navobjects" is the output node of standard BAPI Hrwpc_Rfc_Oadp_Get_Navobjects.

      Regards,

      Gary

  • avatar image
    Former Member
    Jul 04, 2009 at 02:06 PM

    Gary,

    You still need to set the "text" property to the attribute you want to show as the text of the branches.

    Regards,

    Motaz

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Motaz,

      Thanks. I can see the text. Now another question - the records are getting displayed as shown below. All the lines are getting displayed in one go without any collapsabale arrows.

      DownArrow/SideArrow 
      .Line1
      .Line2
      .Line3
      .Line4

      I want the items should get displayed one by one. First we should open Line1. Then there will be collapsable arrow in the left side of Line1. When I will click here, Line2 should be displayed. Again there will be arrow in left side of Line2. When the arrow is clicked Line3 should be displayed and so on.

      DownArrow
        DownArrow/SideArrow .Line1 
           DownArrow/SideArrow.Line2
              DownArrow/SideArrow.Line3
                 DownArrow/SideArrow.Line4

      How we can do so?

      Regards,

      Gary

  • avatar image
    Former Member
    Jul 05, 2009 at 09:30 AM

    Hi Gary,

    You don't need to initialize in the component controller, you can always do it in the view controller.

    What I did is I mapped the output BAPI to a context node in the view (a separate node) and I created new recursive elements and put the data from the BAPI elements inside these recursive elements.

    Regards,

    Motaz

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Motaz,

      The code is working fine for me. But, my problem is that I have display the Oraganization Chart using the Tree. I am using the BAPI "HRWPC_RFC_OADP_GET_navobjects".

      For this, I have already created the WD Project, tree etc.

      I have to use the concept of recrusive tree to show the org chart. For my project, I have to read data from backend using HRWPC_RFC_OADP_GET_navobjects. The challenge is to use the concept of below text file to create Org Chart.

      Can you please help me

      Regards,

      Gary

      Drives = C;D
      C = Documents;Program_Files;Temp;Windows;start.bat
      Documents = Word;calc.xls;db.mdb
      Word = first.doc;second.doc
      Program_Files = Winzip;Accessories
      Winzip = wz.com;wzinst.hlp;test.zip
      Accessories = calculator.exe;notepad.exe;paint.exe
      Windows = Java;Temporary_Internet_Files
      Java = app.java;app.class
      Temporary_Internet_Files = cookie1.txt;cookie2.txt;cookie3.txt;cookie4.txt
      D = Games
      Games = Soccer;Chess
      Soccer = soccer.exe;field.lnd
      Chess = chess.exe

  • avatar image
    Former Member
    Jul 05, 2009 at 09:52 AM

    Gary,

    I am not sure if I can help you with this. The way I did it is as I suggested earlier. I mapped the BAPI to context and I used the context to create the tree. I create recursive elements from the recursive node and fill them with the data from each element from the BAPI. I do this in the "onLoadChildren" action.

    Regards,

    Motaz

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi,

      You can use the model node as data source to populate the tree structure. But you should have the parent and child relationship in that node.

      For exmaple in the Line2 row there should be a field that gives the relationship like Line1 is the parent for Line2. Do you have that kind of relationship in the model node.

      If yes then the data in the model node should be as below

      ModelNode

      -


      > Attributes: Line , ParentId

      -


      > Data--- : Line1 , Root

      -


      > Data--- : Line2 , Line1

      -


      > Data--- : Line3 , Line2

      -


      > Data--- : Line4 , Line3

      Create the TreeNode (value node as below):

      TreeNode:

      -


      > ChildTreeNode (Recursive node of type TreeNode)

      -


      > HasChildern (attribute of type boolean)

      -


      > IsExpanded (attribute of type boolean)

      -


      > Line (attribute of type String)

      create the addChildern method as below:

      private void addChildren(IPrivateTreeView.ITreeNode node,String parentId)
      {
      	for(int iCount=0;iCount<wdContext.nodeModelNode().size();iCount++)
             {
              if(wdContext.nodeModelNode().getParentId.equalsIgnorecase(parentId))
               {
                   IPrivateTreeView.ITreeNodeEleent nodeElement=node.createTreeNodeElement();
                   nodeElement.setLine(wdContext.nodeModelNode().getLine());
                   nodeElement.setHasChildern(childExist(wdContext.nodeModelNode().getLine()));
                   nodeElement.setIsExpanded(false);
                }
             }
      
      }

      Then in the wdDoInit() method you need to call the addChildern() method as below:

      addChildern(wdContext.nodeTreeNode(),"ROOT");

      Write the below code in onActionLoadChildern action:

      onActionLoadChildern(IPrivateTreeView.ITreeNodeElement element)
      {
           addChildern(element.nodeChildTreeNode(),element.getLine());
      }

      code of method childExist():

      private boolean childExist(String line)
      {
       for(int iCount=0;iCount<wdContext.nodeModelNode().size();iCount++)
         {
            if(wdContext.nodeModelNode().getParentId.equalsIgnorecase(line))
            {
             return true;
                 } 
                 else
                {
                 return false;
                }
      }

      In wdModfifyView method as it is in the pdf document::

      Regards,

      Charan