Entering content frame

Procedure documentation Creating Navigation Changes Locate the document in its SAP Library structure

Use

You must define the runtime behavior of the application regarding navigation changes between individual view assemblies in a separate step. The navigation change occurs at runtime when an outbound plug in an action event handler of the view controller is triggered. There are two steps:

·        Action event handler calls outbound plug (programmatic)

·        Outbound plug traces navigation links (declarative)

This indirection during the trigger process of the navigation change ensures that navigation changes can be subsequently modified in a purely declarative way without having to change the source code. The method call that triggers the outbound plug remains unchanged in the source code.

Procedure

A navigation change is usually triggered when the user selects a button. You need to do the following:

...

       1.      Defining an Action Event

       2.      Assign the action event to the onAction event of the Button UI element

       3.      Programmatically trigger the outbound plug (which has at least one navigation link) in an action event handler of the view controller.

Defining an Action Event

You add action events to the Actions tab in the View Designer by choosing New next to the action table and entering a name.

At runtime, the entry is automatically displayed in the field Text on all buttons whose onAction events are bound to the new action event. When the property text of a button is set by the application developer, this mechanism is overridden.

Do not set the flag Without Validation and leave the flag Event handler – Use default for each action event unchanged.

You can use the checkbox Fire Plug to instruct the Web Dynpro code generator during the action event definition to insert the program line for triggering the requested outbound plug in the action event handler.

This graphic is explained in the accompanying text

Define the following action events:

View Name

Name of the Action Events

Text

Outbound Plug to Be

Triggered

Welcome

ExitPressed

Exit Quiz

 

StartPressed

Start Quiz

StartQuizOut

Question

ShowAnswerPressed

Show Answer

ShowAnswerOut

ShowNextQuestionPressed

Next Question

ShowQuestionMarkOut

Answer

EndQuizPressed

End Quiz

EndQuizOut

 

Assigning an Action Event

You assign an action event to the onAction property of a UI element of the type Button in the Properties tab of the View Designer. Select the UI element in the Outline section and select the action event for the property Event ® onAction in the list of all action events that are defined for the view.

Use the following table for naming the action events for the onAction property of the five buttons:

View

UI Element

Action Event to Be Assigned

Welcome

StartQuizButton

StartPressed

ExitButton

ExitPressed

Question

ShowAnswerButton

ShowAnswerPressed

NextQuestionButton

ShowNextQuestionPressed

Answer

EndQuizButton

EndQuizPressed

 

Programmatic Triggering of Outbound Plugs

The Web Dynpro code generator automatically implements the event handler for the event onAction in the individual view controllers for triggering outbound plugs, because you previously selected the corresponding outbound plugs in the checkbox Fire Plug of the Action Wizard.

A method call triggers the corresponding outbound plug, which contains the actual navigation link.

The implementation of the action event onActionStartPressedin the view Welcome for triggering the outbound plug StartQuizOut has been extended by the Web Dynpro code generator, as follows:

/** declared validating event handler */

public void onActionStartPressed(

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

{

  //@@begin onActionStartPressed(ServerEvent)

  wdThis.wdFirePlugStartQuizOut();

  //@@end

}

Programmatic Triggering of the Exit Plug

The user should be able to terminate the Web Dynpro application in the Welcome view. This requires the triggering of the exit plug, which is defined in the interface view. To be able to trigger the exit plug, the controller of the interface view must be defined as the required controller in the Welcome view.

       4.      Open the Welcome view in the View Designer and select the Properties tab. Choose Add next to the Required Controllers table and add the QuizInterfaceView controller.

       5.      Select the Implementation tab and add the following source code for the onActionExitPressed event handler:

/** declared validating event handler */

public void onActionExitPressed(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent

                                wdEvent )

{

  //@@begin onActionExitPressed(ServerEvent)

  wdThis.wdGetQuizInterfaceViewController().wdFirePlugGotoUrl( 

                                              "http://www.sap.com");

  //@@end

}

 

When the user triggers the GotoUrl  exit plug, the Web Dynpro application terminates. The user session also terminates, and the resources required for the session at Web Dynpro runtime are released.

Result

You have defined action events, bound them to buttons, and triggered navigation changes, which have been triggered by the buttons. You have also used the corresponding outbound plug methods for the programmatic triggering of the navigation changes.

You can now observe the runtime behavior of the application at the current development state:

...

       1.      Choose Rebuild Project for your Web Dynpro project.

       2.      Choose Deploy new archive and run in the context menu of the Web Dynpro application QuizApp.

This graphic is explained in the accompanying text       The next section is about controller contexts and data binding.

 

Leaving content frame