Entering content frame

Procedure documentation Initializing Top Level Value Attributes Locate the document in its SAP Library structure

There are four top level value attributes within the Quiz component: NextButtonVisibility, ShowAnswerButtonEnabled, TextMessage, and ExitButtonVisibility.

The value attributes TextMessage and ExitButtonVisibility can be initialized in the wdDoInit() method of theWelcome view controller. This method is called by the Web Dynpro runtime during the creation of the Welcome view.

Implementation in the Welcome view controller

...

//@@begin imports

import com.sap.tc.webdynpro.progmodel.api.WDVisibility;

import com.sap.tc.webdynpro.tutorials.quiz.wdp.IPrivateWelcome;

//@@end

...

 

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

public void wdDoInit()

{

  //@@begin wdDoInit()

  wdContext.currentContextElement().setTextMessage(welcomeMessage);

  wdContext.currentContextElement().setExitButtonVisibility(WDVisibility.NONE);

  //@@end

·        }

The local member variable welcomeMessage is defined in the next chapter.  

This graphic is explained in the accompanying text

The only instance of the root node element can be accessed at runtime using the wdContext.currentContextElement() method. This instance contains the defined structure of value attributes and may contain the defined structure of value nodes. You receive the read and write accesses for the value attributes using the automatically generated Mutator methods, for example, wdContext.currentContextElement().setTextMessage(welcomeMessage).

The remaining value attributes NextButtonVisibility and ShowAnswerButtonEnabled should be initialized when the user navigates from the Welcome view to the Question view for the first quiz question by selecting the Start Quiz button. The corresponding event handler in the Question view controller is the onPlugShowQuestionIn() method, which is called when the user navigates to the Question view.

This graphic is explained in the accompanying text

The wdContext.wdDoInit() method in the Question view controller is only called when the Question view is added to current view group – that is, when the view is visible. The lifetime of the view controller is as long as its view is visible during subsequent view group changes. If a view is no longer in the current view group, its view controller in the Web Dynpro runtime is also deleted until it is requested again within a succeeding view group (another call of the wdDoInit() method).

Implement the following source code in the controller of the Question views:

Implementation in the Question view controller

...

//@@begin imports

import com.sap.tc.webdynpro.progmodel.api.WDVisibility;

import com.sap.tc.webdynpro.tutorials.quiz.wdp.IPrivateQuestion;

//@@end

...

 

/** declared validating event handler */

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

{

  //@@begin onPlugShowQuestionIn(ServerEvent)

  wdContext.currentContextElement().setNextButtonVisibility(WDVisibility.VISIBLE);

  wdThis.wdGetShowAnswerPressedAction().setEnabled(true);

  wdContext.nodeQuizData().moveFirst();   

  //@@end

·        }

 

In the code line wdThis.wdGetShowAnswerPressedAction().setEnabled(true);, the action ShowAnswerPressed is activated. All UI elements with an event bound to this action are automatically activated. In the quiz application, this is the case for the button ShowAnswerButton (Creating Navigation Changes).

Since the first question is to be displayed after calling the Question view, the lead selection of the value node QuizData in the Quiz component controller must be set to the first node element. As a consequence, the attribute values of the first node element of the type QuizData are automatically displayed on the user interface using data binding.

This graphic is explained in the accompanying text  In the last section of this example application, different context state changes are specified using implementation, for example, the setting of new values in value attributes or the changing of the lead selection in the value node QuizData to switch to another question.

  

  

 

Leaving content frame