!--a11y-->
Interaction of the EmailWindow and the
AddressbookWindowTo open and close the address book (AddressbookWindow) and apply the e-mail address from the address book to the EmailView (embedded in the EmailWindow), you must make the following enhancements:
· Enhance the context of the EmailView
· Create onActionShowAddressbookPopup
· Create the event and event handler
· Implement the event handler
· Create and implement the action AddressSelected
To be able to create the address book window and close it again, you must save the window instance in the context of the EmailView.
1. To do this, enhance the context in the EmailView:

Context Element |
Type |
Properties |
Value |
|
Value node |
cardinality |
1..1 |
|
Value attribute |
type |
com.sap.tc.webdynpro. services.session.api.IWDWindow |
The values of the value attribute WindowInstance require a Java Native Type as the data type. Proceed as follows:
1.
To
open the dialog box for selecting the Java Native Type data type,
choose
(in the value column for the property
type).
2. Select the Java Native Type radio button and choose Browse… This opens another window.
3. In the input field, enter IWDWindowfor the value attribute. You can then select IWDWindow in the lower list. Choose OK to confirm.
4. Choose Finish to confirm.
...
1. In the EmailView, create the action ShowAddressbookPopup:
Name of the Action |
Without Validation |
Event Handler |
ShowAddressbookPopup |
unchecked |
onActionShowAddressbookPopup |
2. Bind this action to the To_Button pushbutton:
UI Element Name |
Event Name |
Action |
To_Button |
onAction |
ShowAddressbookPopup |
3. To open the Web Dynpro window with the AddressbookView, add the following program code to the action handler onActionShowAddressbookPopup():
onActionShowAddressbookPopup() |
public void onActionShowAddressbookPopup( com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent ) { //@@begin onActionShowAddressbookPopup(ServerEvent)
//get the repository content at runtime of the Web-Dynpro-Window //“AddressbookWindow” IWDWindowInfo windowInfo = (IWDWindowInfo)wdComponentAPI .getComponentInfo() .findInWindows("AddressbookWindow"); //create the “AddressbookWindow” IWDWindow window = wdComponentAPI.getWindowManager() .createWindow( windowInfo, true); //set the WindowPosition on the screen window.setWindowPosition(300, 150); //and show the window window.open();
// Save WindowInstance in Context wdContext.currentPopupElement().setWindowInstance(window); //@@end } |
You use the method findInWindows() to obtain the Repository content of the Web
Dynpro window AddressbookWindow.
You use the method createWindow() of the IWDWindowManager to create the Web Dynpro window and open() to display it.
To close the window again, you need the window instance. Therefore, this is saved in the context.
If an e-mail address is selected in the AddressbookView, then the EmailView must be informed of this so that it can close the AddressbookWindow and write the e-mail address to the recipient input field. The communication is realized using an event. You create this event in the Component Controller and use the method fireAddressSelected-Event to trigger it. You create the corresponding event handler in the EmailView.
...
1. Open the Component Controller of the PopupComp (Web Dynpro Components à PopupComp à Component Controller).
2. Choose the Events tab page.
3. To create a new event, choose New.
4. Give the event the name AddressSelectedEvent and choose Finish to close.

To enable the AddressbookView to trigger the event AddressSelectedEvent, the Component Controller must have a public method fireAddressSelectedEvent, which triggers the event.
...
1. Choose the Methods tab page.
2. Create the method fireAddressSelectedEvent and choose Finish.

3. Choose the Implementation tab page.
4. To trigger the event, add the following program code to the method fireAddressSelectedEvent:
fireAddressSelectedEvent() |
public void fireAddressSelectedEvent( ) { //@@begin fireAddressSelectedEvent() wdThis.wdFireEventAddressSelectedEvent(); //@@end } |
To enable the EmailView to catch the AddressSelectedEvent, create an event handler in the EmailView:
...
1. Open the EmailView (PopupCompàViewsàEmailView).
2. Switch to the Methods tab page.
3. To create an event handler handleAddressSelectedEvent for the event AddressSelected, choose New.
4. In the wizard that appears, select Event handler and choose Next to confirm.
5. Enter the name handleAddressSelectedEvent and select PopupComp – com.sap.tc.webdynrpo.tutorial.popup as the Event source and AddressSelectedEvent as the Subscribed event. Choose Finish to confirm.

In the event handler handleAddressSelectedEvent of the EmailView, the AddressbookWindow is closed and the e-mail address is written to the recipient input field.
...
1. Switch to the Implementation tab page.
2. Add the following program code to the event handler handleAddressSelectedEvent():
handleAddressSelectedEvent() |
public void handleAddressSelectedEvent( com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent ) { //@@begin handleAddressSelectedEvent(ServerEvent)
//put the selected email into context-attribute “ToAddress” wdContext. currentEmailSettingsElement().setToAddress( wdContext.currentAddressbookElement().getEmail());
//Get “AddressbookWindow” and close it IWDWindow window = wdContext.currentPopupElement().getWindowInstance(); window.close();
//@@end |
You now create and implement the action AddressSelected in the AddressbookView. This triggers the AddressSelectedEvent to the EmailView:
...
1. Open the controller of the AddressbookView (PopupComp à Views à AddressbookView).
2. Switch to the Actions tab page.
3. Create the action AddressSelected:
Name of the Action |
Without Validation |
Event Handler |
AddressSelected |
unchecked |
onActionAddressSelected |
4. Switch to the Layout tab page.
5. Bind the action AddressSelected to the ToolBarButton that you created earlier.
6. Switch to the Implementation tab page and add the following program code to the action handler onActionAddressSelected():
onActionAddressSelected() |
public void onActionAddressSelected( com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent ) { //@@begin onActionAddressSelected(ServerEvent) wdThis.wdGetPopupCompController(). fireAddressSelectedEvent(); //@@end |
This triggers the event
AddressSelectedEvent of the Component Controllers to the
EmailView.
You have created a Web Dynpro window that embeds and implements a Web Dynpro view, which displays an address book.
Next
step:Creating a Confirmation Dialog Box
