on 03-18-2005 4:33 AM
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.