Creating a Component Context and Binding It to the Model

Each Web Dynpro component is supplied with a corresponding Component Controller. This controller is responsible for the acquisition of the data required by the QuickCarRentalService Web service for car reservations. Accordingly, it must be able to depict the corresponding input and output structures of the CarRental model. In order to create a connection between the Component Controller and the model created in the previous step, you will bind the context of the Component Controller to the created model structure using the Data Modeler.

The following figure explains how the structure of the context tree generally results from the model classes and their relations to one another – on the basis of the model binding. 


The structure of your project TutWD_CarRental_Init is currently displayed in the Web Dynpro Explorer.


Adding a Model to the Web Dynpro Component


       1.      Open the Data Modeler through the context menu entry  Open Data Modeler of the node CarRentalComp.

       2.      In the toolbar on the left, choose the  Add an existing model to the component icon.

The icon will then be highlighted in gray.

       3.      Place the cursor on the  Used Models area and left-click.

       4.      Select the CarRentalModel checkbox and confirm by pressing OK.

The structure of the Web Dynpro component CarRentalComp will look like this in the Data Modeler:

Binding the Component Controller Context to the Web Service

You can declare the binding between the context of the component controller and the created CarRentalModel – in a very simple manner from the Data Modeler you just started – using a service controller template:


       1.      In the Data Modeler, choose the icon for Component Controller and start the respective context menu.

       2.      From the context menu, choose the option Apply Template.

       3.      Choose the Service Controller template in the displayed wizard and then Next.

       4.      Now choose the model class Request_QuickCarRentalServiceViDocument_saveBooking and navigate further using Next.

       5.      In the following input dialog, select all the model nodes and model attributes.

In general, it is appropriate to keep the similarity of names between the model classes and parameters and the corresponding context nodes or context attributes. However, the root node for the model is derived directly from the model main class Request_QuickCarRentalServiceViDocument_saveBooking with the same name: . In this case, it is better to take a shorter name, such as SaveBooking.

       6.      Now edit the new name SaveBooking in the first line underneath the table column Name.

       7.      Close the template wizard using Finish and save the project.


From the generated model classes, you have now defined a structure of context elements (consisting of model nodes and model attributes) in the component controller CarRentalComp, and you have also bound these to the respective parameters of the model classes.

Also, with the help of the service controller template in the component controller, you have generated the code in the two methods wdDoInit() und executeSaveBooking( ).


In every controller there are predefined locations where you – as application developer – can insert the source code. The standard methods wdDoInit() andwdDoExit() belong to these locations. wdDoInit() is always controlled if the controller is instanced. For this reason, you must remember that at this point there is an object which – at runtime – represents the entire input, including all the input parameters for calling the Web Service business method. In addition, you will need a further controller method in which the actual call of the Web service method is triggered. This is done in the method named execute_Save( ). Since you have implemented the template wizard, you do not need to implement these methods in the component controller yourself. The generated lines are discussed below:

Set up the access to the Web Service model within the method wdDoInit(). Here you define a request object that – at runtime – represents the input page of the Web service method. This object must also be bound to the model node SaveBooking (that was declared at Design time).


  public void wdDoInit()


    //@@begin wdDoInit()

   //$$begin Service Controller(-1547658955)

   wdContext.nodeSaveBooking().bind(new Request_QuickCarRentalServiceViDocument_saveBooking());




The actual Web service is now called through the execute() method call of the model object currently selected in the context model node. The data stored in the controller context is a copy of the data stored in the model – that is, the one does not directly reference the other. Therefore, the controller context does not yet contain the returned results of the Web service call executed previously and stored in the model. For this reason, the model node Response (exists as inner node underneath the SaveBooking node in the context) is explicitly invalidated. The result is that the response data currently stored in the model is transferred to the respective context node element.


  //@@begin javadoc:executeSaveBooking()

  /** Declared method. */


  public void executeSaveBooking( )


    //@@begin executeSaveBooking()

   //$$begin Service Controller(-1285036589)

   IWDMessageManager manager = wdComponentAPI.getMessageManager();





   } catch(Exception ce) {

      manager.reportException(ce.getMessage(), false);






Next Step:

Mapping the View Context onto the Component Context