cancel
Showing results for 
Search instead for 
Did you mean: 

TreeByNestingTableColumn question

Former Member
0 Kudos

I have followed the following tutorial, to create the TreeByNestingTableColumn:

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webdynpro/tutorial on creating a tree structure in a table - 27.htm

Everything works fine, however, how can I trigger an event to the controller, when te user selects a row in the table.

I need to fire the event, and let the controller know the ID of the selected row.

Any Ideas on this?

Accepted Solutions (1)

Accepted Solutions (1)

former_member182372
Active Contributor
0 Kudos

Hi Harm,

Isn`t it described in Valery`s blog? /people/valery.silaev/blog/2005/06/20/master-of-columns-part-ii

Code from blog`s example which returns selected node elemenent


  private IPrivateTreeTableCV.IEntriesElement currentEntry()
  {
  	try
  	{
  		IWDNodeElement el;
  		for 
  		(
  			el = wdContext.nodeEntries().getTreeSelection();
  			!( el == null || el instanceof IPrivateTreeTableCV.IEntriesElement);
  			el = el.node().getParentElement()
  		);
  		return (IPrivateTreeTableCV.IEntriesElement)el;
  		
  	}
  	catch (final WDContextException ex)
  	{
  		return null;
  	}
  }

And to fire event when user selectes a row you need to define onLeadSelect event by table.

Best regards, Maksim Rashchynski.

Former Member
0 Kudos

Thanks for your quick reply.

However it did not work.

I do not have a getTreeSelection() method. I guess this is because I'm using a TreeByNestingTableColumn and not a Tree.

I tried the following:


  private IPrivateResultView.IBomTableElement currentEntry()
	{
		int leadSelection = wdContext.nodeBomTable().getLeadSelection();
		return (IPrivateResultView.IBomTableElement) wdContext.nodeBomTable().getElementAt(leadSelection);
	}

But, this code always returns 0.

Any suggestions?

former_member182372
Active Contributor
0 Kudos

Hi Harm,

Method getTreeSelection() is member of IWDNode class. So, it should be accessable from every context node. On which SP level you are?

Best regards, Maksim rashchynski.

Former Member
0 Kudos

Hi Harm,

The id what you need is part of the element in the recusive node.

If so you have to do the following.

Create a method With parameter element.

Connect that method to onLeadSelect.

use the following code inside the method.

{

String iD = element.getId();

wdThis.controller.methodname(id);

}

Regards

Ayyapparaj

Former Member
0 Kudos

I tried what you said:

public void onActionSelect(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, com.asml.tpd.app.wdp.IPrivateResultView.IBomTableElement selectedElement )

{

//@@begin onActionSelect(ServerEvent)

String parent = selectedElement.getID();

}

However, when onActionSelect is called (I debugged this),

selectedElement is null. Therefore a NPE arrises on selectedElement.getID();

What is going wrong here?

Can you please help?

former_member182372
Active Contributor
0 Kudos

Hi Harm,

I have just downloaded and imported tutorial project to my NWDS and this piece of code works:


private IPrivateTreeTableView.ICatalogEntriesElement currentEntry()
{
  try
  {
	  IWDNodeElement el;
	  for 
	  (
		  el = wdContext.nodeCatalogEntries().getTreeSelection();
		  !( el == null || el instanceof IPrivateTreeTableView.ICatalogEntriesElement);
		  el = el.node().getParentElement()
	  );
	  return (IPrivateTreeTableView.ICatalogEntriesElement)el;
	
  }
  catch (final WDContextException ex)
  {
	  return null;
  }
}

Don`t really understand why you don`t like it.

Best regards, Maksim Rashchynski.

Former Member
0 Kudos

Maksim,

I sincerely appreciate your effort.

However, I cannot get your code to compile. I tried the following:


//@@begin javadoc:onActionSelect(ServerEvent)
	/** Declared validating event handler. */
  //@@end
  public void onActionSelect(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, com.asml.tpd.app.wdp.IPrivateResultView.IBomTableElement selectedElement )
  {
    //@@begin onActionSelect(ServerEvent)
    

	try
	  {
			  IWDNodeElement el;
			  for
			  (
			  		  el = wdContext.nodeBomTable().getTreeSelection();
					  !( el == null || el instanceof IPrivateTreeTableView.ICatalogEntriesElement);
					  el = el.node().getParentElement()
			  );
			  return (IPrivateTreeTableView.ICatalogEntriesElement)el;
	       
	  }
	  catch (final WDContextException ex)
	  {
			  return null;
	  }

	}

NWDS reports: The method getTreeSelection() is undefined for the type IPrivateResultView.IBomTableNode ResultView.java TestWebservice/gen_wdp/packages/com/asml/tpd/app line 302

Any suggestions?

former_member182372
Active Contributor
0 Kudos

Hi Harm,

could you please send me your project to rastchinskym AT mail DOT ru. I will take a look.

former_member182372
Active Contributor
0 Kudos

Hi Harm,

Seems like SP11`s version of Node implementation really doesn’t have getTreeSelection (in spite of setTreeSelection is there). So, you can try following code:


final IPrivateTreeTableView.ICatalogEntriesElement getRecursiveLeadSelection(

IPrivateTreeTableView.ICatalogEntriesNode __node )
{
      int leadSelection = __node.getLeadSelection();

      if( leadSelection!=IWDNode.LEAD_SELECTION ) {
IPrivateTreeTableView.ICatalogEntriesElement element = getRecursiveLeadSelection(                        __node.nodeChildCatalogEntries( leadSelection ) );

            if(element==null) {
                  return __node.currentCatalogEntriesElement();
            } else {
                  return element;
            }
      } else {
            return null;
      }
}

Best regards, Maksim Rashchynksi.

Answers (0)