!--a11y-->
Creating Controller result.do for the Results List 
Use
This controller controls the results list of your page, which should be displayed within an HTMLB table view. If a book in the results list is then selected by clicking on it, the lower section of the page should display detailed data about the book (see also
Creating Controller detail.do for the Detail Display and Creating View detail.htm for the Detail Display).Procedure
This is the most difficult view because in addition to methods
DO_REQUEST and DO_HANDLE_EVENT, method IF_HTMLB_TABLEVIEW_ITERATOR~RENDER_CELL_START must also be overwritten. The structure of type BSBOOKDATA, which represents a book that is found, contains normal string fields for the title, sub-title, publisher and so on, as well as an internal table (type AUTHORTAB) of authors, since one book can have more than one author(see also Data Model for the Bookshop Tutorials). This internal table can only be represented as a column in the table view using custom rendering functions. We will do this in the second step: Processing Custom Rendering for the Author Column.We will overwrite methods
DO_REQUEST and DO_HANDLE_EVENT and add the necessary attributes to the controller class.Method
DO_REQUEST is executed when the controller is called (here in the Main View default.htm), method DO_HANDLE_EVENT is called if an event occurs (clicking on a table entry).Method DO_REQUEST
The coding for this method looks like this:
|
method DO_REQUEST . data: result_view type ref to if_bsp_page. data: main_controller type ref to cl_bsp_controller2. data: search_controller type ref to CL_BSP_TUT_SEARCH. data: isbn_tab type isbn_tab. data: bookcat_tab type BSBOOKCAT_TAB. * get reference to search_controller main_controller ?= m_parent. if main_controller is bound. search_controller ?= main_controller->get_controller( controller_id = 'search' ). if search_controller is bound. isbn_tab = search_controller->isbn_tab. endif. endif. if isbn_tab is not initial. CALL METHOD cl_book_shop=>get_book_data EXPORTING isbn_tab = isbn_tab IMPORTING bookcat_tab = bookcat_tab EXCEPTIONS empty_input_table = 2 invalid_isbn = 4. else. clear me->cata_id. endif. me->bookcat_tab = bookcat_tab. result_view = create_view( view_name = 'result.htm' ). result_view->set_attribute( name = 'bookcat_tab' value = bookcat_tab ). result_view->set_attribute( name = 'iterator' value = me ). call_view( result_view ). endmethod. |
The first thing to note is how the controller obtains the information from the controller of search
search.do. To do this it must get the reference to the search controller from the main controller, and then transfer the ISBN table of the books that are found from that controller.Using the same method as in the old tutorial
Our First Online Bookshop a table is generated from the ISBN table with all data for the books that are found.Lastly, view result.htm is called. An iterator must be specified as an attribute, as well as the structure with the book data. The iterator is required for custom rendering the author column (see also
Custom Rendering for the Author Column).Method DO_HANDLE_EVENT
This method contains the following coding:
|
method DO_HANDLE_EVENT . class cl_book_shop definition load. DATA: table_event type ref to CL_HTMLB_EVENT_TABLEVIEW. data bookcat_tab type bsbookcat_tab. data wa type bsbookdata. data cata_id type bsindex. data rowselection type I. bookcat_tab = me->bookcat_tab. IF htmlb_event is bound AND htmlb_event->name = 'tableView'. table_event ?= htmlb_event. rowselection = table_event->selectedrowindex. read table bookcat_tab index rowselection into wa. me->cata_id = wa-cata_id. endif. endmethod. |
The books that were found are located in the internal table
bookcat_tab. If a row is clicked on, the corresponding book index is set in the attribute cata_id.This is then required by the controller for the detail display
detail.do.Additional Attributes of the Controller Class
You must give the controller class the following additional attributes:
|
Attribute |
Type |
Visibility |
Reference Type |
Description |
|
CATA_ID |
Instance Attribute |
Public |
BSINDEX |
Bookshop index |
|
S_BOOKDATA |
Instance Attribute |
Public |
BSBOOKDATA |
Structure for transferring all relevant data for a book |
|
BOOKCAT_TAB |
Instance Attribute |
Public |
BSBOOKCAT_TAB |
Table for book and catalog data |
The structures are taken from the book data model in the other tutorials, see
Data Model for the Bookshop Tutorials.Result
You now have the controller for the results list with the exception of the method for custom rendering for the author column (
Custom-Rendering for the Author Column). You can leave this for now and finish the tutorial. This just means that there are no authors in the column provided.![]()
Now create the corresponding view:
Creating View result.htm for the Results Page