Event handler in web dynpro abap between 2 components.
STEP 1. Create a web dynpro component .
2.Go to view and create a text view and a button.
3. Create a action for the button.
4.After clicking on OK button, the method will be created .
5.now go to component controller and go to events tab.
6.Give an event name and tick the check box Interface.
7. Now go to view and to the Action of the Button.
And go in to the click method of the button.
Just raise the event which we declared in the component controller.
Source code :
DATA lo_COMPONENTCONTROLLER TYPE REF TO IG_COMPONENTCONTROLLER .
lo_COMPONENTCONTROLLER = wd_this->get_componentcontroller_ctr( ).
The concept is , whenever the button is clicked the event e1 will be raised.
8. Now save and activate the component.
10. Now create another component as shown below.
11.In used web dynpro components , use the previous component that we have created .. as shown.
So that the 1st component can be used …
12.Now go to view main.
Create a view container element:
13.Now go to properties tab and click on create button
Choose the interface controller of used component.
And click on tick mark.
Now you can see the below screen shot. Where component 1 is accessible with in the view of component 2.
14. Now go to methods tab.
Create a new method (Event handler) and choose the drop down as event instead of method.
Now go to event column and choose f4 help, where you can choose the event which is declared in the component 1.
Click on tick mark. Now this method is the event handler for the event E1.
So when ever event E1 Raises, this method will be triggered..
Now go inside the event handler method .
Write some Success message..
So when ever the event is triggered , the success message will be displayed.
Source Code :
* get message manager
data lo_api_controller type ref to if_wd_controller.
data lo_message_manager type ref to if_wd_message_manager.
lo_api_controller ?= wd_This->Wd_Get_Api( ).
CALL METHOD lo_api_controller->GET_MESSAGE_MANAGER
MESSAGE_MANAGER = lo_message_manager
* report message
CALL METHOD lo_message_manager->REPORT_SUCCESS
MESSAGE_TEXT = ‘ Event handler method is triggered sucessfully’.
15 Now go Windows ..
Right click on vc(View container) and choose embed.
Now choose the f4 help on view to be embedded and choose component 1’s view
Click on tick mark..
So that the Component 1’s view will be embedded with component 2’s view container.
Now save the web dynpro component and activate it..
Create a web dynpro application and save it.
Right click on web dynpro application and test it .
Now the output screen is.
Just click on the button,
It will trigger the even handler method and a success message will be displayed.
Hope it is useful..