cancel
Showing results for 
Search instead for 
Did you mean: 

Finding the event source

Former Member
0 Kudos

Hi,

I have a scenerio where I am dynamically creating UI elements and what to bind the action to an event handler.

How do I know which of the UI elements that I have added has triggered the event? I tried adding a parameter to the event handler and tried running the code as follows :

for (....) {

IWDLinkToAction lTA = (IWDLinkToAction) view.createElement(IWDLinkToAction.class,"LTA" + i);

lTA.setText("<some string>");

IWDAction action = wdThis.wdGet<>Action();

IWDParameters paras = action.getActionParameters();

paras.addParameter("<para name>", <value>);

lTA.setOnAction(action);

viiew.addElement(lTA);

}

But this always gives the latest set value (I understand now that is obvious). What is the way out.....is there a way I can find the trigger source.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Nirav,

I tried to simulate your situation, i.e. creation of links dynamically and processing them through a common action. I have created an action with one string parameter which will recieve the value to understand from which link click its getting activated. So I am pasting the code I have written in wdDoModifyView and onActionProcessLink methods. ProcessLink is the action method name I am using.

public static void wdDoModifyView(IPrivateTestCompView wdThis, IPrivateTestCompView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)

{

//@@begin wdDoModifyView

if(firstTime){

IWDTransparentContainer root = (IWDTransparentContainer)view.getRootElement();

for(int i=0;i<5; i++){

IWDAction linkAction = wdThis.wdCreateAction(IPrivateTestCompView.WDActionEventHandler.PROCESS_LINK,"");

IWDLinkToAction link = (IWDLinkToAction)view.createElement(IWDLinkToAction.class,"Link"+i);

link.setText("Link Number "+i);

link.setOnAction(linkAction);

link.mappingOfOnAction().addParameter("linkClicked","Clicked Link "+i);

root.addChild(link);

}

}

//@@end

}

//@@begin javadoc:onActionProcessLink(ServerEvent)

/** Declared validating event handler. */

//@@end

public void onActionProcessLink(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, java.lang.String linkClicked )

{

//@@begin onActionProcessLink(ServerEvent)

wdComponentAPI.getMessageManager().reportSuccess("PARAM : "+linkClicked);

//@@end

}

Its working fine and depending upon the parameter value I can understand from which link this action has been activated. From the message I am printing in the action method I can get this info.

Hope it helps!!!

Shubhadip

Message was edited by: Shubhadip Ghosh

Former Member
0 Kudos

Thanks a million. It works now, but can you explain the logic behind this processing.

What I follow from the code is that the event handler can be called by different actions which can to assigned to the UI elements along with the parameters to be passed. Am I correct?

Former Member
0 Kudos

Hi Nirav,

lets keep things simple. I have an action handler method. For my purpose I need this action handler method to process more than one event of the user form. How will I know that which event is calling it? The answer is through a parameter which will tell the origin of the event like in the example we sent the name of the link. Had there been two buttons with two commands we had sent the button name or some string which identifies what action is to be done. So from our code we created the action object, mapped it with the user element (link here). Then we created one parameter for this action where we are passing two parameters, the first is the parameter name for the action handler method and second is the parameter value. So inside the action handler method its upon us what should we do with it.

Regards,

Shubhadip

Former Member
0 Kudos

Why do you <b>create</b> a separate action for each link?

Armin

Answers (0)