Entering content frame

Procedure documentation Implementing the Controller of the ControlPanel View Locate the document in its SAP Library structure

Prerequisites

This graphic is explained in the accompanying text

You have declared the actions CreateComponent and DeleteComponent in the controller of the ControlPanel view.

This graphic is explained in the accompanying text

You have declared the usage of the inner Web Dynpro component Internal in the embedding Web Dynpro component Embedder.

This graphic is explained in the accompanying text

You have declared the component and controller usage of the inner Web Dynpro component in the controller of the ControlPanel view.

This graphic is explained in the accompanying text

You have declared in the controller of the ControlPanel view the method reactToComponentEvent, which subscribes as an event handler to the event InnerEvent of the inner Web Dynpro component.

This graphic is explained in the accompanying text

You have built the view context for the ControlPanel view.

This graphic is explained in the accompanying text

The structure of your project WebDynpro_Eventing is currently displayed in the Web Dynpro Explorer.

 

Procedure

The implementation of the ControlPanel view controller is restricted to the action event handler for creating and deleting the used inner Web Dynpro component Internal, to the event handler of the event sent by the embedded Web Dynpro component, and to the generic event handler wdDoModifyView() for directly modifying UI element instances.

Creating the Used Inner Web Dynpro Component

In the action event handler onActionCreateComponent(), a Web Dynpro component specified by the component usage is instantiated.

...

...

       1.      Switch to the Implementation perspectives view of the ControlPanel view controller.

       2.      In the onActionCreateComponent() method, add the following source code:

//@@begin javadoc:onActionCreateComponent(ServerEvent)

/** declared validating event handler */

//@@end

public void onActionCreateComponent(

              com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

  //@@begin onActionCreateComponent(ServerEvent)

  wdThis.wdGetInternalComponentComponentUsage().createComponent();

 

  // Set status of Action objects. Button events bound to these actions are

  // accordingly enabled or disabled.

  wdThis.wdGetCreateComponentAction().setEnabled(false);

  wdThis.wdGetDestroyComponentAction().setEnabled(true);

  //@@end

}

Buttons can be easily activated or deactivated by activating or deactivating the corresponding action objects to which they are bound in the view controller.

The event onAction of the button CreateButton is bound to the action CreateComponent, for example. In the view controller implementation, the runtime instance of this action can be accessed using wdThis.wdGetCreateComponentAction() to then modify its state using the method setEnabled(boolean). On the user interface, all UI elements bound to this action are automatically adapted to the state of the corresponding action object. 

       3.      In the method wdDoInit(), add the following code to initialize the action DestroyComponent:

//@@begin javadoc:wdDoInit()

/** Hook method called to initialize controller. */

//@@end

public void wdDoInit()

{

  //@@begin wdDoInit()

  wdThis.wdGetDestroyComponentAction().setEnabled(false);

  //@@end

}

Deleting the Used Inner Web Dynpro Component

       4.      In the onActionDestroyComponent() method, add the following source code:

//@@begin javadoc:onActionDestroyComponent(ServerEvent)

/** declared validating event handler */

//@@end

public void onActionDestroyComponent(

              com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

  //@@begin onActionDestroyComponent(ServerEvent)

  wdThis.wdGetInternalComponentComponentUsage().deleteComponent();

  wdThis.wdGetCreateComponentAction().setEnabled(true);

  wdThis.wdGetDestroyComponentAction().setEnabled(false);

  wdContext.currentContextElement().setEventParameter("");

  //@@end

}

This graphic is explained in the accompanying text

After deleting the instance of the used Web Dynpro component, the Web Dynpro runtime automatically replaces its interface view with an empty view. Therefore, the application developer does not need to navigate to such an empty view.

Vice versa, the interface view is displayed on the user interface as soon as the corresponding component life cycle starts (provided that no other view is currently set to visible).

Implementing the Event Handler of the InnerEvent Event

To display on the user interface the parameter value of the InnerEvent event sent by the inner Web Dynpro component, set the value attribute EventParameter in the event handler reactToComponentEvent().

       5.      In the reactToComponentEvent() method, enter the following source code:

/@@begin javadoc:reactToComponentEvent(ServerEvent)

/** declared validating event handler */

//@@end

public void reactToComponentEvent(

              com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent,

              java.lang.String text )

{

  //@@begin reactToComponentEvent(ServerEvent)

  wdContext.currentContextElement().setEventParameter(text);

  //@@end

}

 

Result

Congratulations, you have now completed the development of the actual Eventing example application. To be able to test its runtime behavior, you must first generate Java classes, deploy the software deployment archive that belongs to the Web Dynpro project, and start the application in the Web browser:

This graphic is explained in the accompanying text

This graphic is explained in the accompanying text Now continue with External Context Mapping.

 

Leaving content frame