Creating a BSP using the Model View Controller(MVC) technique

Tutorial 3 - Event handling and calling a new view Step 1 - Redefine DO_HANDLE_EVENT event Return to the controller class you created in tutorial 1, accessed via the controller page (i.e. main.do) and double clicking on the cc name ( ZCL_CONTROLLER_01 ). Go into change mode and find the DO_HANDLE_EVENT method and redefine it. Step 2 - Insert code in to DO_HANDLE_EVENT Enter the following ABAP code which handles a button click event:

method DO_HANDLE_EVENT . *CALL METHOD SUPER->DO_HANDLE_EVENT * EXPORTING * EVENT = * HTMLB_EVENT = ** HTMLB_EVENT_EX = * GLOBAL_MESSAGES = * RECEIVING * GLOBAL_EVENT = * . DATA: button_event TYPE REF TO CL_HTMLB_EVENT_BUTTON. "date event DATA: date_event TYPE REF TO CL_HTMLB_EVENT_DATENAVIGATOR. "button event * Check if event being processed is a button event IF htmlb_event IS BOUND AND htmlb_event->name = 'button'. * Use widening cast to take generic event to specific event (button event) * - Basically moves current event structure into button event structure, * - so that the button event now contains the relevant data button_event ?= htmlb_event. * * Contains value store in the 'onClick' parameter on page view if button_event->server_event = 'myClickHandler'. page = 'page2.htm'. endif. ENDIF. * Check if event being processed is a date event * - the below code is simply for further demonstration of above syntax IF htmlb_event IS BOUND AND htmlb_event->name = 'dateNavigator'. date_event ?= htmlb_event. ENDIF. endmethod.

Step 3 - Create attributte to store next page value Return back to Class interface and define a new class attributte as type string to store next page value! Step 4 - Modify DO_REQUEST method You now need to modify the DO_REQUEST code so that it calls the event handling and controls which page to display based on the new page variable/attribute. The event handling is called using the 'dispatch_input( )' command.

METHOD do_request . *CALL METHOD SUPER->DO_REQUEST * . DATA: r_view TYPE REF TO if_bsp_page. * Calls event handler DO_HANDLE_EVENT dispatch_input( ). IF page EQ 'main1.htm' or page EQ space. r_view = create_view( view_name = 'main1.htm' ). r_view->set_attribute( name = 'p_ord' value = me->r_model ). ELSEIF page = 'page2.htm'. r_view = create_view( view_name = 'page2.htm' ). r_view->set_attribute( name = 'p_ord' value = me->r_model ). ENDIF. ** Create object r_view with view_name main1.htm ** Layout is provided by view main1.htm * r_view = create_view( view_name = 'main1.htm' ). * r_view->set_attribute( name = 'p_ord' * value = me->r_model ). call_view( r_view ). ENDMETHOD.

Step 5 - Create second View Firstly save and activate the controller class. The next stage is to create the second view which is executed from within DO_REQUEST. This will need to be called 'page2.htm' unless you modify the code you have just placed in the DO_REQUEST method. The simplest way to do this is to copy your existing view (main1.htm), You might want to change some text slightly so that you can distanguish between the 2 page. i.e. change PO text to 'Purchase order2'. Step 6 - Save and activate Ensure you save and activate all the objects that have been changed during this tutorial. Tutorial 1 Tutorial 2 Tutorial 3


Related Articles

Javascript to capture when a user closes or leaves sap bsp html page
Using AJAX functionality within our SAP BSP
Close BSP Session (type 'Pluggin HTTP') including when in SAP portal
SAP BSP to auto select region when user selects country using HTML and Javascript
HTML and Javascript code to force enter key to perform tab
JavaScrip command getElementById useful examples
MVC BSP input field - Demonstrate how to retrieve a value entered into text input field
Allowing multiple instances of a BSP application to be run by a user
Execute Standard SAP Transaction from BSP using dynamically created shortcut
Uplaod file within SAP BSP application using HTML and ABAP coding
UUseful SAP BSP application code - ABAP, HTML, HTMLB, Javascript, CSS
Creating a BSP Application class to help store and pass data betwenn your BSP pages
Training Course and Workshop Booking Form
BSP checkboxes using HTML and the OnInputProcessing BSP Event
BSP checkboxes using HTML and the OnInputProcessing BSP Event
Check HTML checkbox is checked using Javascript within your SAP BSP
BSP Dropdown List - create a BSP dropdown list which allows user selection!!
ABAP BSP to allow user to select from SAP HR org structure - CSS file
Java script to display tree structure on your SAP BSP web page
Create a Simple BSP - Simple BSP to display text and call section BSP page using HTML
SAP BSP Training course booking - Creating an example training course booking form using BSP
Creating an SAP BSP which executes an ABAP report to retrieve data for use within BSP application
org selection BSP - detials.htm page
Display page of the SAP BSP example application to store favourite tcodes as a cookie
Execute.htm page of the SAP BSP example application to store favourite tcodes as a cookie
Favourites cookie bsp - initial page to display input fields and retrieve user input
BSP using cookies - Demonstrate use of cookies within a BSP to store user favourits
ABAP Export data to memory - Demonstrate use of ABAP program to retrieve data for use in BSP
MVC BSP HTMLB input field - Demonstrate how to retrieve a value entered into text input field
BSP development using standard HTML code instead of Business HTML (HTMLB)
Business HTML (HTMLB) - List of business HTML tags you can use within your BSP
Adding JavaScript to BSP (HTML) pages - Shows how to add javascript to your BSP pages
Example JavaScript code which can be added to your BSP application
BSP MIME Objects for Org. search application
Call onInputProcessing event from SAP BSP page via href or button
Organisation selection BSP - close internet window using javascript
Organisation selection BSP - get server side cookie ( get_server_cookie )
orgaisation selection BSP - set and get server side cookie ( set_server_cookie )
Display orgaisation selection BSP
BSP which allows HR Organisation Structure search and selection using javascript
Organisation update program - get server side cookie ( get_server_cookie )
BSP to capture user entry into HTML input fields
Capture BSP radiobutton selection using HTML and the OnInputProcessing BSP Event
BSP checkboxes using HTML and the OnInputProcessing BSP Event
Stateful and stateless BSP applications
Get user entry into HTML input fields with SAP BSP
Javascript to capture when a user closes or leaves sap bsp html page
Creating a BSP using the Model View Controller ( MVC ) technique
Using SAP Model View Controller (MVC) development techniques to develop BSPs
Adding a JavaScript date selection field to a BSP
Creating a BSP using the Model View Controller ( MVC ) technique
Creating a BSP using the Model View Controller ( MVC ) technique
Retrieve value from input text field within a model view controller ( MVC) BSP
Web Application Development - Example code and information on development using BSP
SAP BSP / Business Server Pages combine ABAP and other web technologies such as HTML, CSS
BSP development screen - developing application using business server pages
Standard Program created in SE38 or SE80