Creating Actions and Implementing Navigation

To navigate from one view to the next, you need an appropriate action, which you bind to a UI element event (such as a button’s event onAction ). You then need to implement the event handler, which reacts to this action and triggers a view change by firing an outbound plug.

Prerequisites

You have created navigation links between the views.

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

Procedure

...

       1.      To launch the View Designer, double-click the StartView node in the project structure or in the Data Modeler view.

       2.      Choose the Actions tab.

       3.      Choose the New pushbutton.

You can create a new action in the wizard that appears.

       4.      Enter the name Go for this new action. In the field Text enter Go for the text to be displayed on all UI-elements with events bound to this action. Leave the Event handler option unchanged. Assign the plug ToResultView as a Fire plug and choose Finish.

The new action, Go, and its associated event handler onActionGo are displayed in the list of actions.

       5.      Repeat the above steps as appropriate to create the Back action for the ResultView, this time assigning the plug ToStartView as a Fire plug and entering Back in the Text field.

       6.      Save the new metadata by choosing the icon  (Save All Metadata) from the toolbar.

Result

You have created the Go and Back actions. The implementation of the navigation was automatically inserted to the associated event handlers.

To check the generated source code for event handler onActionGo(), choose the Implementation tab for the StartView. The method contains only the single line wdThis.wdFirePlug<Name_of_Outbound_Plug>().

/** declared validating event handler */

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

{

   //@@begin onActionGo(ServerEvent)

   wdThis.wdFirePlugToResultView();

   //@@end

}

To trigger navigation from the StartView to the ResultView using the outbound plug ToResultView, the application calls the outbound plug method wdFirePlugToResultView(). The predefined private variable wdThis is used for this method call. The wdThis variable is always required whenever you need to make method calls to the view controller’s private interface IPrivate<Name_of_View>.

To check the generated source code for event handler onActionBack(), choose the Implementation tab for the ResultView.

/** declared validating event handler */

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

{

   //@@begin onActionBack(ServerEvent)

   wdThis.wdFirePlugToStartView();

   //@@end

}

In the next step, you need only assign these actions to the appropriate buttons in the view layout and the navigation part of your Welcome application will have been defined completely.

Next step:

Designing a View Layout