Show TOC

LifetimeLocate this document in the navigation structure

Use

Controller

Controller

You determine the lifetime of components or their controllers in the usual way using the Properties tab page of the controller. You can specify the lifetime as one of the following three options in Status:

  • To page change

  • For the duration of the request

  • For the duration of the session

The setting is usually To Page Change.

By default, the lifetime of controller instances is limited to the one call. If the controller instance is passed with id, then its lifetime is the same as that specified in the controller's properties ( Properties tab). The id can be specified as follows:

  • From a page or a view:

    <bsp:call/goto comp_id = "id">

  • From a controller or a page event:

    create_controller(...controller_id='id')

    Caution

    The controller_id or the comp_id of the <bsp:call> element must not contain an underscore ('_ '). The underscore is reserved as a separator between controllers.

The lifetime of the top-level controller ranges from the first CREATE_CONTROLLER for a subcontroller to DELETE_CONTROLLER for the subcontroller.

If subcontrollers should occasionally be hidden, so that they are not involved in event handling for a while, then use method CONTROLLER_SET_ACTIVE. A controller that is set to inactive in this way will not be called for input processing.

Note

The controller is only hidden; the controller instance is not deleted.

Views

Views
Caution

This section concerning the lifetime of views concerns the use of MVC in SAP Web AS 6.20 up to and including Support Package 9.

Unlike controllers or pages, views have only a very short lifetime. Their life cycle looks as follows:

  1. They are created.

  2. They are supplied with parameters.

  3. They are called.

  4. They are now no longer required and therefore expire, since views cannot be reused.

    Views therefore only exist for the duration of the call, that is, they are destroyed after they have been called.

As a developer of BSP applications with MVC, you must explicitly recreate the view, since you cannot reuse it in a controller. The following provides an example of correct and incorrect coding:

Use:

Do not use:

DATA: view TYPE REF TO if_bsp_page.
view = create_view( view_name = 'main.htm' ).
                           
DATA: view TYPE REF TO if_bsp_page.
IF view IS NOT BOUND. " or IS NOT INITIAL.
   view = create_view( view_name = 'main.htm').
ENDIF.
                           
Caution

In any case, the view must be explicitly recreated before it is used.

DATA: view TYPE REF TO if_bsp_page.

view = create_view( view_name = 'main.htm' ).

" ... set attributes ....

call_view( page ).

CLEAR view.