!--a11y-->
Creating a Model 
A model enables the user to access business data that is outside the Web Dynpro application from within the application. In this tutorial, the business data that belongs to the car reservation is made accessible through a special Web service.
Within a Web Dynpro component, business data is stored in separate context structures (consisting of context nodes and context attributes). The link between the context elements contained there and the business data in an existing model can be set up using the communication classes and auxiliary classes required for this purpose. You can use the Web Dynpro tools to generate such a model for a known Web service description. The model mainly consists of special model classes that you can use to link context structures to the model.
Below you will learn how you can generate such a model, on the basis of a Web Service description of a Web service deployed on the J2EE engine.
|
|
You have deployed the EAR file for the QuickCarRental example application with the Web Service QuickCarRentalService on theSAP J2EE engine. |
|
|
The structure of your project TutWD_CarRental_Init is currently displayed in the Web Dynpro Explorer. |
To create a model that is based on a certain Web service, you only require the URL address through which the corresponding WSDL description can be accessed. If the address is known, you can then easily create an appropriate model easily.
...
1. In your Web-Browser, open the page with the address http://<host>:<port>/QuickCarRentalService/Config1
2. In the displayed overview under WSDL, choose the link.

3. Copy the URL from the address line in the browser window: http://<host>:<port>/QuickCarRentalService/Config1?wsdl
In this way, you have a URL address through which the WSDL description of the Web service QuickCarRentalService is accessible.
...
1. In the project structure, expand the node Web Dynpro ® Models.
2.
From the context
menu, choose
Create Model. In order to start the appropriate
wizard.
3. Choose the Import Web Service Model option, followed by Next.
4. Enter the name CarRentalModel as the model name and com.sap.tut.wd.carrental.model as the package name.
5. Choose the Local File System option or the URL and confirm by selecting Next.

6. Now enter the URL address you just copied for the WSDL description of the QuickCarRental Web service into the field Wsdl and select Next.

7. Close the input dialog by selecting Finish.
Starting from the WSDL description of the CarRental Web service, you have created a model named CarRentalModel in your Web Dynpro project. In accordance with the MVC paradigm, the model was not simply generated as part of the Web Dynpro component, but as an independent development object. Accordingly, you will have to explicitly create this model for the Web Dynpro component before it can be used there.
All the generated
model classes are now executed within the project structure in the Web
Dynpro Explorer under the node
Model.

The model is represented here, for the most part, by a set of model classes, including their relations. As a result of the proxy generation, you have - for each of the 3 business methods from the Web service - a request and a response class as well as an additional class that represents a complex data type.
This figure corresponds exactly to the Web service virtual interface definition. To verify this, you only need to start the corresponding editor in the J2EE Explorer.
You can follow up the meaning the relations have for the model classes quite easily:
The request class
of the save method Request_<Web service document
name>_saveBooking is in the source-to-target relation for the
respective response class Response_<Web service document
name>_saveBooking. You can find it through the node
Response.
The corresponding
response class, in turn, references the class
ComplexType_QuickBookingModel through the relation node
Result. You can follow this up easily
through the Properties View.

This class, however, represents the complex data type QuickBookingModel, which – in turn – corresponds exactly to the return type of the SaveBooking method.
The relations represent not only a hierarchy of the model classes, but also have far-reaching effects on the programming model. You always call a business method using the corresponding request object. For example, if a booking is to be executed using the Save method, this is based on an instance of the class Request_<Web service document name>_saveBooking. In another step, you will create an instance for this class before you send off the actual method call. You call the business method using the method execute(), which belongs to the respective request class. Whenever execute() is called, an instance of the response classes associated through the relation is created in each case. In this case, not only one instance of the class Response_<Web service document name>_saveBooking is created, but an additional instance for the class ComplexType_QuickBookingModel associated through its relation. A renewed method call would therefore trigger another response object and thus also another result object.

To keep this example application as simple as possible, you will use in this tutorial only the model classes required for storing a reservation.
Creating a Component Controller Context and Binding it to the Model
