Start of Content Area

Procedure documentation Programming Context State Changes Locate the document in its SAP Library structure

Use

The states, which are stored in the different contexts, are changed according to the events triggered by the user in the event handlers of the view controllers Welcome.java andQuestion.java.

The UI element properties bound to the view context (such as text of the TextView UI element or visible for the Button UI element) must be adjusted to each new situation on the user interface and the navigation in the list of QuizData node elements is necessary to display the desired question-answer pair on the user interface.

Procedure

Add the code lines contained in the following tables to the appropriate user coding areas of the individual view controllers.

View-Controller Welcome.java

You must initialize the view context in the Welcome view controller again by selecting the Start Quiz button (display the welcome message, hide the exit button for exiting the application). When terminating the quiz, the exit button and a goodbye message must be displayed after selecting the End Quiz button in the Answer view. The text messages are stored in two string variables welcomeMessage and endMessage, which are only visible in the view controller.

Implementation in the View Controller Welcome.java

...
/** declared validating event handler */
public void onActionStartPressed(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
  //@@begin onActionStartPressed(ServerEvent)
  
wdDoInit(); 
  wdThis.wdFirePlugStartQuizOut();
  //@@end
}
...
/** declared validating event handler */
public void onPlugEndQuizIn(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
  
//@@begin onPlugEndQuizIn(ServerEvent)
  
wdContext.currentContextElement().setTextMessage(endMessage);
  wdContext.currentContextElement().setExitButtonVisibility(WDVisibility.VISIBLE);
  
//@@end
}
...
/*
 * The following coding section can be used for any Java coding that has 
 * not to be visible to other controllers/views or that contains constructs
 * currently not supported directly by Web Dynpro (such as inner classes or
 * member variables etc.). </p>
 *
 * Note: The content of this section is in no way managed/controlled
 * neither by the Web Dynpro Designtime nor the Web Dynpro Runtime. 
 */
//@@begin others
private String welcomeMessage = 
  
"Welcome to this short quiz about navigation and view sets in Web Dynpro!";
private String endMessage = 
  
"Goodbye, we hope you enjoyed this short Web Dynpro quiz application!";
//@@end

View Controller Question.java

When the user selects the Next Question button, the view QuestionMark is called. In the context, you must reference to the subsequent QuizData node element to display the next question text on the user interface using data binding. The following code moves the lead selection of the QuizData value node to the next position and therefore points to the next available node element of the type QuizData.

wdContext.nodeQuizData().moveNext();

If the lead selection points to the last node element, the Next Question button must be hidden by assigning the value WDVisibility.BLANK to the NextButtonVisibility value attribute.

We recommend you deactivate the Show Answer button by deactivating the corresponding action ShowAnswerPressed.

Implementation in the View Controller Question.java

/** declared validating event handler */
public void onActionShowNextQuestionPressed( 
  com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent)
{
  
//@@begin onActionShowNextQuestionPressed(ServerEvent)
  
wdContext.nodeQuizData().moveNext(); 
  wdThis.wdGetShowAnswerPressedAction().setEnabled(
true);
  
//--- hide Next button, if last question is reached
  
if (wdContext.nodeQuizData().getLeadSelection() == wdContext.nodeQuizData().size()-1) {
    wdContext.currentContextElement().setNextButtonVisibility(WDVisibility.BLANK);  
  }        
  wdThis.wdFirePlugShowQuestionMarkOut();    
  
//@@end
}
...
/** declared validating event handler */
public void onActionShowAnswerPressed(com.sap.tc.webdynpro.progmodel.api.
  IWDCustomEvent wdEvent)
{
  
//@@begin onActionShowAnswerPressed(ServerEvent)
  //disable ShowAnswer button
  
wdThis.wdGetShowAnswerPressedAction().setEnabled(false);
  
//--- trigger navigation by firing outbound plug
  
wdThis.wdFirePlugShowAnswerOut();
  
//@@end
}

 

This graphic is explained in the accompanying text       You have now successfully developed an extended Web Dynpro application and already become familiar with several components of the Web Dynpro programming model. You integrate the Web Dynpro application in the SAP Enterprise Portal in the next step.

 

End of Content Area