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.

Prerequisites

You started the J2EE Engine.

You have deployed the EAR file for the QuickCarRental example application with the Web Service QuickCarRentalService on theSAP J2EE engine.

You have made sure that the proxy settings of your Workbench are the same as the settings in your Intranet. Check these settings in the Developer Studio under Window а Preferences а Workbench а Proxy Settings.

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

Procedure

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.

Determining the URL Address of the WSDL Description

...

...

                            a.      In your Web browser, open the page with the address http://<host>:<port>/QuickCarRentalService/Config1

                            b.      Choose the link Overview on the displayed homepage. 

                            c.      Copy the URL stated there for WSDL to your clipboard.  (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. 

Generating a Model from the WSDL Description

...

                            a.      In the project structure, expand the node Web Dynpro ® Models.

                            b.      From the context menu, choose  Create Model. In order to start the appropriate wizard.

                            c.      The appropriate wizard appears. Choose the Import Web Service Model option, followed by Next.

                            d.      Enter the name CarRentalModelas the model name and com.sap.tut.wd.carrental.modelas the package name.

                            e.      Choose the Local File System option or the URL and confirm by selecting Next.

 

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

                            g.      In the displayed dialog box, choose Finish.

Result

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.

All the generated model classes are now executed within the project structure in the Web Dynpro Explorer under the node  Model.

 

Besides, as part of the model definition another node named Logical Ports has been generated. Based on the used Web service URL, here the Target Address is specified that is used for accessing the Web service at runtime.

 

Discussion of Result

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, in the J2EE perspective simply open the respective editor in the J2EE Explorer for the defining EJB project J2EE_QuickCarRentalEjb.

  

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_QuickBookingModelassociated 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.

Next Step:

Creating a Component Controller Context and Binding it to the Model