Start of Content Area

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

There are three top level value attributes within the quiz component: NextButtonVisibility, TextMessage, and ExitButtonVisibility. The value attributes TextMessage and ExitButtonVisibility can be initialized in the wdDoInit()method of the controller of the view Welcome. This method is called by the Web Dynpro runtime during the creation of this view.

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

 

Implementation in the View Controller Welcome.java

...

//@@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 section. 

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 value attribute NextButtonVisibility is to be initialized whenever the user chooses the Start Quiz button in the Welcome view to display the first quiz question in the Question view. 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 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 view Question:

 

Implementation in the View Controller Question.java

 

...

//@@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.   

 

End of Content Area