Show TOC

Implementing View ControllersLocate this document in the navigation structure

Procedure

Overview

Implementing Hook Methods

Task 1: Implementing the Action Event Handler onActionSave()

The action Save is associated with the event handler onActionSave() . In this method the application logic for the action Save can be implemented.

SampleView.java

//@@begin javadoc:onActionSave(ServerEvent)

/**

* Declared validating event handler.

*

* @param wdEvent generic event object provided by framework

*/

//@@end

public void onActionSave( com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionSave(ServerEvent)

...

//@@end

}

Using the IPrivate-API

Task 2: Dynamically subsribing an event handler to an event

You can dynamically subsribe the view controller's event handler onSomeEvent() to the event SomeEvent (exposed by the component controller) at runtime with the generic component controller API IWDComponent . For this purpose the generated event- and event handler constants must be used.

SampleView.java

//@@begin javadoc:wdDoInit()

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

//@@end

public void wdDoInit()

{

//@@begin wdDoInit()

IWDEventId eventId = wdThis.wdGetSampleCompController().WD_EVENT_SOME_EVENT;

IWDEventHandlerId eventHandlerId = wdThis.WD_EVENTHANDLER_ON_SOME_EVENT;

wdComponentAPI.addEventHandler(eventId,eventHandlerId);

//@@end

}

Task 3: Disabling the Save Action Object

The object instance of the defined action Save can be accessed in the IPrivate -API of the view controller.

SampleView.java

wdThis.wdGetSaveAction().setEnabled(false);

Using the IPublic-API of another controller

Task 4: Firing the suspend plug of a window conroller

You can directly fire the suspend plug Suspend defined in the window controller SomeWin in a view controller. To invoke the IPublic -API of the window controller a corresponding controller usage relation must be defined.

SampleView.java

IPublicSampleWin winPublicAPI = wdThis.wdGetSampleWinController();

winPublicAPI.wdFirePlugSuspend(someSuspendURL);

// direct access

wdThis.wdGetSampleWinController().wdFirePlugSuspend(someSuspendURL);

Task 5: Firing event SomeEvent defined in the component controller

Events which are defined in non-view controllers cannot be fired by other controllers because the IPublic -API does not expose a corresponding wdFireEventXY() -method by default. Consequently you must declare a public method fireSomeEvent() in the component controller which fires the event SomeEvent and which can be invoked by the view controller. To invoke the IPublic -API of the component controller a corresponding controller usage relation must be defined.

SampleView.java

wdThis.wdGetSampleCompController().fireSomeEvent()

SampleComp.java

//@@begin javadoc:fireSomeEvent()

/**

* Method declared by application.

*/

//@@end

public void fireSomeEvent( ) {

//@@begin fireSomeEvent()

wdThis.wdFireEventSomeEvent();

//@@end

}

Using the Generic Controller APIs

Task 6: Changing the keyboard input focus on the client

Change the keyboard input focus to the UI element whose primary purpose is to raise an event bound to the action Save.

SampleView.java

//Assumption: Only one single UI element is bound to action Save

wdControllerAPI.requestFocus(wdThis.wdGetSaveAction());

Task 7: Accessing the Message Manager

The IWDMessageManager -API is exposed to all controllers in a Web Dynpro component via the generic component controller API IWDComponent . This interface can directly be accessed with the shortcut variable wdComponentAPI .

SampleView.java

IWDMessageManager msgMgr = wdComponentAPI.getMessageManager();

Task 8: Accessing the Generic Controller API of the embedding Window

Invoke the generic IWD WindowController -API of the window controller instance which embeds this view you .

SampleView.java

IWDWindowController wdwController = wdControllerAPI.getWindowController();