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 default.do 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 default.do.
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).
Layout of default.bsp