Entering content frame

Procedure documentation Creating View detail.do for the Detail Display Locate the document in its SAP Library structure

Use

This controller class is responsible for determining the detailed data on a book in the results list that is selected. When users choose Order this book, page corder.htm should also be displayed.

Procedure

Name the controller class such as CL_MVC_TUT_DETAIL and overwrite the methods DO_REQUEST and DO_HANDLE_EVENT. Then add the attributes that are also required to the class.

Method DO_REQUEST

Overwrite the method as follows:

method DO_REQUEST .

  data: detail_view type ref to if_bsp_page.

  data: main_controller type ref to cl_bsp_controller2.

  data: result_controller type ref to CL_TUT_MVC_RESULT_CO.

  data: cata_id TYPE bsindex.

  data: s_bookdata type BSBOOKdata.

* get reference to result_controller

  main_controller ?= m_parent.

  if main_controller is bound.

    result_controller ?= main_controller->get_controller(

                         controller_id = 'result' ).

    if result_controller is bound.

      cata_id = result_controller->cata_id.

    endif.

  endif.

  clear s_bookdata.

  if cata_id is not initial.

* if books found and one selected, retrieve book details and display

    CALL METHOD cl_book_shop=>get_item

      EXPORTING

        cat_id = cata_id

      IMPORTING

        bookdata = s_bookdata

      EXCEPTIONS

        empty_input = 2.

    detail_view = create_view( view_name = 'detail.htm' ).

    detail_view->set_attribute(

                 name = 's_bookdata'

                 value = s_bookdata ).

    call_view( detail_view ).

  else.

    detail_view = create_view( view_name = 'about.htm' ).

    call_view( detail_view ).

  endif.

endmethod.

As with the Controller result.do for the Results List you must get the information first of all from a different controller, in this case from result.do, from which the detailed information for the book was requested.

Then use the usual method of class S_BOOK_SHOP (see also Data Model for the Bookshop Tutorials), to determine the detailed data for the specified catalog ID.

When the view is called, the following special feature occurs:

if no book was found (that is, the catalog ID is empty) for which detailed data were determined, the system should not display any detailed information that may be available from a previous search. This is why view about.htm (information on the bookshop) is called in this case.

The catalog is set only if you click on a book. The detail data are then determined and are transmitted to view detail.htm.

Method DO_HANDLE_EVENT

Overwrite this method to react to the Order this book pushbutton.

method DO_HANDLE_EVENT .

  if htmlb_event is bound and htmlb_event->server_event = 'order'.

    navigation->goto_page( 'corder.htm' ).

  endif.

endmethod.

Page corder.htm is not a view but a usual BSP with flow logic. You redirect to the page using navigation->goto_page.

Additional Attributes of the Controller Class

Create the following additional attributes in controller class CL_MVC_TUT_DETAIL:

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

Result

You have implemented the controller for determining the detail data.

This graphic is explained in the accompanying text

Now create the two possible views that can be called.

Creating View detail.htm for the Detail Display

Creating View about.htm for the Detail Display

Leaving content frame