BSP / HowTo: Exploring BSP Development with MVC 2b
- BSP / HowTo: Exploring BSP Development with MVC – Introduction, Tables, Table Types and sample data.
- Part 2 – Building the App.
- BSP / HowTo: Exploring BSP Development with MVC 2a – Building your Model
- BSP / HowTo: Exploring BSP Development with MVC 2b – Building your Controllers and Classes
- BSP / HowTo: Exploring BSP Development with MVC 2b_1 – Building your Controllers and Classes
- BSP / HowTo: Exploring BSP Development with MVC 2b_2 – Building your Controllers and Classes
- BSP / HowTo: Exploring BSP Development with MVC 2b_3 – Building your Controllers and Classes
- BSP / HowTo: Exploring BSP Development with MVC 2c – Building your views
- BSP / HowTo: Exploring BSP Development with MVC 2d – Building your views
- Part 3 – Working the App
- BSP / HowTo: Exploring BSP Development with MVC 3a – Display it and entering
- BSP / HowTo: Exploring BSP Development with MVC 3b – Editing and adding categories and subjects
- BSP / HowTo: Exploring BSP Development with MVC 4 – OTR
- BSP / HowTo: Exploring BSP Development with MVC 5 – Conclusions
Building your Controllers and Classes
Now for the most part we tend to start off with building our pages then the controller behind it, simply because it is often easier in terms of variable names and programming. You do your layout then build up the backend logic. But since I’m writing this after the fact, OK, twice after the fact I decided to do it in reverse order. Now please pay close attention to these parts as they are different than the original programming in many ways. The basic logic is there but the rest is quite different.
Now as you can see from this image I’ve added in several more classes than we had previously. Which means that yes with an MVC concept there is a bit more programming, but the benefits I hope you will see by the time we are done with the whole process.
What we have here is a Controller class for each section of the application, within these classes all of the logic and processing we will want to accomplish is done. Now I’ve purposely kept these to a minimum in order to give each of you a chance to play around and find ways of improving not only performance but also the logic.
Each of the following classes have the Superclass of CL_BSP_CONTROLLER2 and some have even the Interface IF_HTMLB_TABLEVIEW_ITERATOR. Using the IF_HTMLB_TABLEVIEW_ITERATOR interface will allow us to create our Table Iterators as part of the class itself, useful when the View you are associating with the class has only one table on it.
So let’s get started with creating our first controller. Basically on your BSP application select “Create” then “Controller”.
Once it is there then give it the “Controller” name, again try for a naming convention that will make sense later on.
Once you type that in and save it then you can double click on the controller name and it will prompt you to create the controller class.
Now go ahead and create each of the following controllers and then their respective classes. Once that is done we’ll go through and fill in our data, attributes, interfaces and coding.
Now that they are all there let’s go to the our Main controller, ZFAQ_C_CL_FAQ.
Attributes
These are basically like our Page attributes.
MODEL | Instance Attribute | Private | Type Ref To | ZFAQ_CL_M |
LT_TAB | Instance Attribute | Protected | Type | STRING |
CTR_INTRO | Instance Attribute | Protected | Type Ref To | CL_BSP_CONTROLLER2 |
CTR_CAT | Instance Attribute | Protected | Type Ref To | CL_BSP_CONTROLLER2 |
CTR_SUBJECT | Instance Attribute | Protected | Type Ref To | CL_BSP_CONTROLLER2 |
CTR_SDNLINKS | Instance Attribute | Protected | Type Ref To | CL_BSP_CONTROLLER2 |
CTR_SDN | Instance Attribute | Protected | Type Ref To | CL_BSP_CONTROLLER2 |
CTR_INDEX | Instance Attribute | Protected | Type Ref To | CL_BSP_CONTROLLER2 |
Now we are going over to the Methods tab and we are going to “redefine” the methods that we will be using.
DO_INIT |
> method DO_INIT . model ?= create_model( class_name = ‘ZFAQ_CL_M’ ctr_intro ?= create_controller( controller_name = ‘intro.do’ ctr_intro->set_model( model_id = ‘mf’ ctr_cat ?= create_controller( controller_name = ‘cat.do’ ctr_cat->set_model( model_id = ‘mf’ ctr_subject ?= create_controller( controller_name = ‘subject.do’ ctr_subject->set_model( model_id = ‘mf’ ctr_sdnlinks ?= create_controller( controller_name = ‘sdnlinks.do’ ctr_sdnlinks->set_model( model_id = ‘mf’ ctr_sdn ?= create_controller( controller_name = ‘sdn.do’ ctr_sdn->set_model( model_id = ‘mf’ ctr_index ?= create_controller( controller_name = ‘index.do’ ctr_index->set_model( model_id = ‘mf’ endmethod. |
DO_INITATTRIBUTES |
> method DO_INITATTRIBUTES . lt_tab = request->get_form_field( ‘faq_tabs’ ). endmethod. |
DO_REQUEST |
> method DO_REQUEST . * Data definitions * Start event handling * Create view default_view->set_attribute( name = ‘lv_tab’ * Call view if lt_tab is not initial. endmethod. |
DO_HANDLE_EVENT |
> method DO_HANDLE_EVENT . * Object definitions lt_event = cl_htmlb_manager=>get_event_ex( request ). tabStrip ?= CL_HTMLB_MANAGER=>GET_DATA( request = request IF lt_event IS NOT INITIAL. lt_tab = tabStrip->selection. ENDIF. endmethod. |
Now before we move to far further along, I want to bring your attention back to DO_INIT and to DO_REQUEST. In DO_INIT you’ll notice we define in there the rest of our controllers, the reason for this is because they are basically sub controllers and exist only within the realm of the main controller and therefore can not be accessed on their own. In the DO_REQUEST you’ll notice a line dispatch_input() now this method controls the processing of each controller and should only be listed within the main controller and not the sub controllers. Another important item to remember to to check the “Stateful” option in your BSP Application.
Otherwise the data that we set in the Model will not stay and we’ll loose the values each time the page is worked with.
So with those items in place we can now finish the rest of our controllers.
ZFAQ_C_CL_INTRO
Attributes
MODEL | Instance Attribute | Private | Type Ref To | ZFAQ_CL_M |
Methods
DO_REQUEST |
> method DO_REQUEST . * Data definitions * Create view * Call view endmethod. |