Entering content frame

Procedure documentation Interaction of the EmailWindow and the AddressbookWindow

To 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

 

Procedure

Enhancing the Context of the EmailView

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:

This graphic is explained in the accompanying text

 

Context Element

Type

Properties

Value

This graphic is explained in the accompanying text Popup

Value node

cardinality

1..1

This graphic is explained in the accompanying text WindowInstance

Value attribute

type

com.sap.tc.webdynpro. services.session.api.IWDWindow

Assigning a Java Native Type as the Data Type to the Value Attribute WindowInstance

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 This graphic is explained in the accompanying text (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.

 

Creating onActionShowAddressbookPopup()

...

       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

}

This graphic is explained in the accompanying text 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.

 

Creating the Event and Event Handler

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.

Creating the Event in the Component Controller

...

       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.

This graphic is explained in the accompanying text

Creating the Method fireAddressSelectedEvent

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.

This graphic is explained in the accompanying text

       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

}

Creating the Event Handler in the EmailView

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.

 

This graphic is explained in the accompanying text

 

Implementing the Event Handler

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

}

 

Creating and Implementing the Action AddressSelected

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 graphic is explained in the accompanying text This triggers the event AddressSelectedEvent of the Component Controllers to the EmailView.

 

Result

You have created a Web Dynpro window that embeds and implements a Web Dynpro view, which displays an address book.

This graphic is explained in the accompanying text Next step:

Creating a Confirmation Dialog Box

  

  

 

Leaving content frame