Calling the Execute Method

In the previous step, you implemented the public component controller method sendEmail()to trigger the actual Web Service call in it.

 

//@@begin javadoc:onActionSendMail(ServerEvent)

/** Declared validating event handler. */

//@@end

public void sendEmail() {

  //@@begin onActionSendEmail(ServerEvent)

  IWDMessageManager msgMgr = wdComponentAPI.getMessageManager();

  

  try {

    // call Email Web Service and update dependent model node ўResponseў

    wdContext.currentWebServiceEmailElement().modelObject().execute();

    wdContext.nodeResponse().invalidate();

    ...

  } catch(Exception ex) {

    msgMgr.reportException(ex.getLocalizedMessage(),true); 

  }  

  //@@end

} 

 

To understand the two important code lines wdContext.currentWebServiceEmailElement().modelObject().execute();and wdContext.nodeResponse().invalidate();  see the figure below:

The actual Web service call is executed via calling the execute()method of the executable model object (1) which is currently referenced in the context model node (2). This already contains the reservation data entered by the user (through data binding and context mapping). The generation of the model object (1) and its binding to the node WebServiceEmail was implemented before in the method wdDoInit().

After calling the execute() method of the executable model object, the Web-Service returns a corresponding response object (3). The relation (5) of the executable model object (1) thereupon points to this second model object. However, the model node element (4) in the controller context does not yet point automatically to the corresponding response object (3) in the model. Due to this fact, you as an application developer, have to explicitly invalidate the model node Response (contained as an inner node below the node WebServiceEmailin the context). This is executed with the code line wdContext.nodeResponse().invalidate(). Thus, the Web Dynpro runtime environment is told to track the corresponding relation (5) during access to the response node element (4). In doing so, the reference of the response node element (4) in the context is adjusted to the response object (3) returned from the Web Service in the model. For that purpose, the Web Dynpro runtime uses the Supplying-Relation-Role –defined in the model node Response -, which is equivalent to the relation between the model classes Request_SendEmailPortType_sendEmail and Response_SendEmailPortType_sendEmail).

The returned result (in the example application this is just a single integer value) is then displayed in an appropriate message text in the message bar of the Web Dynpro application.