cancel
Showing results for 
Search instead for 
Did you mean: 

Subscribe to events on runtime

Former Member
0 Kudos

Hi,

I need some help on dynamic creation of embedded components.

I'm trying to create any number of embedded components (inner components) -each time the user clicks a button- and inserting them in a tabstrip into de embedder component (outer component). Morover, each inner component could fire a server-side event that the outer component must catch and take an accion.

Up to now, I solved the issue of creating the inner components and adding them to the tabstrip. But I don't know how to subscribe an event handler (declared in the outer component at disign time) to the events of the inner components (this must be done at runtime).

I've tryed something like this:


IWDCustomEventInfo   eInfo = wdThis.wdGet<inner_component>Interface().getEventInfo();
IWDEventHandlerInfo ehInfo = wdControllerAPI.getControllerInfo().findInEventHandlers("<my_event_handler>");
IWDController	controller = wdThis.wdGet<inner_component>Interface().wdGetAPI();

wdComponentAPI.addEventHandler(eInfo, ehInfo, controller);

But it didn't work. I got the error:


java.lang.ClassCastException
	at com.sap.tc.webdynpro.progmodel.controller.Component.addEventHandler(Component.java:717)

I would appreciate any help.

Best regards,

Juan José García Samartino.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Deyang,

With the information you gave me I solved the problem of the exception, but it still doesn't work.

The problem is that when I click the button that fires the exception nothing happens. I know that the event is being fired because I see it in the debugger, but the code on the event handler is never executed.

I think there's a mistake in the parameters I'm passing when I declare the event handler.

To complete the parameters of the method "addEventHandler" I used my original variables but with a small modification:


<b>IExternal<Inner>Interface InnerInterface = (IExternal<Inner>Interface) InnerComponentUsage.getInterfaceController();</b>
<b>IWDCustomEventInfo   eInfo = InnerInterface.getEventInfo();</b>
IWDEventHandlerInfo ehInfo = wdControllerAPI.getControllerInfo().findInEventHandlers("<name_of_my_event_handler>");
IWDController	controller = wdComponentAPI;
	 
wdComponentAPI.addEventHandler(eInfo, ehInfo, controller);

The method "getEventInfo" of the interface is a method I created that returns de event info of the event that I'm firing. It returns:


wdControllerAPI.getControllerInfo().findInEvents("<name_of_inner_event>");

Do you have any idea why it is not working?

Thanks for your help!

Best regards,

Juan Jose Garcia Samartino.

Former Member
0 Kudos

Juan,

Do the following (I've introduced extra-variables for clarity):


/* -begin event source */
/* your dynamically created usage */
final IWDComponentUsage source = InnerComponentUsage;
final IWDCustomEventInfo eventInfo 
  = source
      /* info about component usage */
      .getComponentUsageInfo() 
        /* then about used WD component / interface */
        .getUsedComponent() 
          /* next about it external interface */
          .getInterfaceController() 
            /* lastly about event */  
            .findInEvents(<name-of-your-event>);
/* -end of event source- */

/* -begin event listener- */
final IWDController listener = wdControllerAPI;
final IWDEventHandlerInfo handlerInfo 
  = listener
      .getControllerInfo()
        .findInEventHandlers
          ("<name_of_my_event_handler>");
/* -end of event listener- */

/* -bind event source and listener- */
source.addEventHandler
( 
  eventInfo, handlerInfo, listener
);

Valery Silaev

EPAM Systems

http://www.NetWeaverTeam.com

Former Member
0 Kudos

Hi Valery,

Thank you a lot. Your solution worked perfectly!

Best regards,

Juan Jose Garcia Samartino.

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Teecheu,

Thanks for your answer.

I've created the event handler in the embedder component at design time, but I don't know how to subscribe that event handler to the events of the inner components that I create on runtime.

The main problem is that I don't have the component usages of the inner components available on design time (I also create them on runtime).

To be able to create the event handler I used a "template" inner component usage (the same "template" usage I use to create the other inner component usages on runtime as copies of this one), but the problem is that this event handler is never called when an inner component fires an event. The only way it works is when the "template" inner component fires an event, but it doesn't work with the copies.

Do you (or anyone) know to solve this problem?

Best regards,

Juan José García Samartino.

Former Member
0 Kudos

Hi,

I think if you want to subscribe the outerComponent's event handler to the events of the inner components, you can try the following code:


IExternalDummyComp2Interface dummy2Interface = (IExternalDummyComp2Interface) wdThis.wdGetComp2UsageComponentUsage().getInterfaceController();
  	wdComponentAPI.addEventHandler(dummy2Interface.WD_EVENT_TEST_EVENT, wdThis.WD_EVENTHANDLER_TEST_EVENT_HANDLER);

Here DummyComp is an outer Component and DummyComp2 is an inner Component.

Hope it works!

Best regards

Deyang

Former Member
0 Kudos

Hi,

I guess your problem is not on the dynamic creation of embedded components, but rather the handling of event in the embedding component.

In your embedding component view, did you create any event handler? If not, you should. This event handler will automatically create a method in the view implementation console where you can "take an action."

Hope it helps,

Teecheu