Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

The Model View Controller (MVC) design pattern contains a clear distinction between processing control, data model and displaying the data in the interface. These three areas are formally distinguished from each other by three objects: model, view and controller. As a result, you can easily split Web applications into logical units.

In this tutorial I'll show you how to use the MVC to separate the whole BSP application into a main default controller and view, 2 sub controllers and views search and result, and the data is from model class, how easy to maintain the whole application without reading data from the html form. I'll also show you how to use the cookie from the browser side and the server side in case the connection is interrupted. For example, if the customer is in the middle of using the application and then go to visit another web site or navigate to another web application for the functional reason , or on the portal navigate to another application, then come back again, all the detail information are still there. The client finished the work, a few days later he comes back but he had already forgot the information. Thanks to the cookie on the browser and on the server side which still retain the relevant information. Cookie is quite useful on the complicated situation on portal.

The model is used as an application object of the application data administration. It responds to information requests about its status, which usually come from the view, as well as to statements for status changes, which are usually sent by the controller. In this way, only the model is used to process data internally, without making reference to the application and its user interface.
There can be different views for a model, which can be implemented using different view pages.

I Create  model sub class zcl_bsp_model_oo_mvc  for cl_bsp_model2, add attributes mv_carrid type carrid,  mt_sflight type table sflight, method fill_sflight ,  inside method I call the persistence class zcl_persist_sflight based on the table sflight. If you are interested in persistence class, you can check my tutorial of internet performance tool on web application.

The controller interprets and monitors the data that is input by the user using the mouse and the keyboard, causing the model or the view later to change if necessary. Input data is forwarded and changes to the model data are initiated. The controller uses the model methods to change the internal status and then informs the view about this. This is how the controller determines reactions to the user input and controls processing.  The view and the controller together form the user interface.

Controller: Goto SE80 create bsp application zbsp_OO_MVC,  then create default.bsp and controller and generate the class zcl_bsp_ctrl_oo_mvc_default which is the subclass of cl_bsp_controller2 , add page attribute model type ref to zcl_bsp_model_oo_mvc

Overwrite method do_request of

Method do_request.

Data: view type ref to if_bsp_page.

If me->model is initial.

Me->model ?=create_model(model_id = 'M1' class_name = 'ZCL_BSP_MODEL_OO_MVC').



If is_navigation_requested() is not initial. Return. Endif.

View = create_view(view_name = 'default.bsp').

View->set_attribute(name='MODEL' value = me->model).



The view handles the graphical and textual output at the interface and therefore represents the input and output data in each interface element, such as pushbuttons, menus, dialog boxes and so on. The view takes of visualization. To visualize the status, the view queries the model, or the model informs the view about possible status changes. In the main view I call 2 sub controllers: search and result. In the default.bsp I also add the page fragment javascript.htm, which I add the javascript  about set the cookie on the web page.

Layout of default.bsp

Client side cookie: is a variable that is stored on the visiter's computer, each time the same computer requests a page with a browser, it will send the cookie too, normally cookie is used for the password or date. In this tutorial  I show you how the computer remember the last changed data, in the Layout of javascript.htm, I set the browser side cookie, the browser offer the value for the field automatically, so even if the user is lost in the navigation on the portal.

  • No labels