cancel
Showing results for 
Search instead for 
Did you mean: 

Calling an event from it's handler

Former Member
0 Kudos

Hi.

I'm working with several event handlers (IWDEventHandlerInfo), and I want to execute the events from their handler variables.

Is it possible? How can it be done?

Thanks.

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Thanks for all your replys.

I had a form with several buttons, that trigger a validity check (same event for all buttons). At some condition, it was supposed to display a message with OK and Cancel buttons, and clicking OK would trigger a plug, and in other cases it should just trigger a plug event (different plug for every button).

So I have to write the logic to determine the correct plug twice:

once in order to get the handler, and after that, if the condition wasn't met, to fire the plug.

So I thought that when I have the handler, I could just use it to fire the plug, but apperantly that's impossible.

Best regards,

Udi.

Former Member
0 Kudos

Yes, its possible.

we can execute events from their handler variables.

we know that If a Uielement associated with an action,every time that event raised on the client a corresponding rountrip to the server will occur and the corresponding Eventhandler is called.

so First create a reference to the action Eventhandler using IwdEventhandler.

Using this reference create and enable an action.

and assign this action to uielements which will raise events.

Inthis way we can execute events by calling Eventhandlers.

Regards

sowmya

Former Member
0 Kudos

Thanks,

But what I want is to do this by code, not by relating it to a UI element. I want to do this directly from the instance variable, like from one of it's methods.

Can it be done this way?

Former Member
0 Kudos

Hi ,

ya both ways you can work as per your requirement.

First way is to use (action)Event handler and in this case there will be a IEvent handler and this event handler will be called by a UI element. (for example button) . where on button click this (action)event handler will be called and the line of code will be executed.

OR

Second way is to create a method and write the code in the method, In this case this method should be called by either

wdinit of view controller or component controller and the code you have written will get executed with the initialization of the view or the load event of the application respectively.

you can choose any of the ways or both as per your requirement in your application...

hope this help you...

Please reward points,if the answer is helpfull.

Regards,

Gunja

Former Member
0 Kudos

Hi Udi,

I don't think it is possible the way you want, not without messing with web dynpro internals.

Why are you trying to do this? Maybe if you give us more details on your requirements we can help you with a more polished solution.

In the mean time, consider this approach:

1. For each event handler you intend to call, create an implementing (private) method with a standard name, i.e.

// implementing method: 
 private void handle<eventName>() {
 } 
 // event handler
 void onAction<eventName>(IWDCustomEvent e) {
     handle<eventName>();
 }

I'm assuming you are not passing any parameter to the implementing method.

2. Define a map field in the private section, and in wdDoInit fill the map with pair of event handler infos and implementing method


// wdDoInit
...
eventToMethod = new HashMap();
Iterator it = wdThis.wdGetAPI().getViewInfo().getViewController().getEvents().iterator();
while(it.hasNext()) {
  IWDCustomEventInfo event = (IWDEvent)it.next();
  eventToMethod.put(
    wdThis.wdGetAPI().getViewInfo().getViewController().findInEventHandlers("onAction" + event.getName()),
    this.getClass().getMehod("handle" + event.getName(), new Class[]{}));
}
...

// private section
private HashMap eventToMethod;

3. When you need to call a method from an event handler info, do this

Method m = (Method)eventToMethod.get(eventHandlerInfo);
m.invoke(this, new Object[]{});

Former Member
0 Kudos

I am not getting the exact requirment. Can you give more details.

Former Member
0 Kudos

Thanks for your answers.

I have some event handlers, of type IWDEventHandlerInfo, which are set from wdControllerAPI().getViewInfo().getViewController().findInEventHandlers("onActionBack"); (for example)

If I want to call this event, I would do wdThis.onActionBack(wdEvent);

But I want to call this event from the event handler instance.

Is it possible?

Best regards,

Udi.

jnmurthi
Participant
0 Kudos

hi

[Event Handling|http://help.sap.com/SAPHELP_NW04S/helpdata/EN/5d/64a0ed34c59e4c9754be5c0759c7c0/content.htm]

Regards,

Murthy.