Show TOC

Calling ComponentsLocate this document in the navigation structure

Use

You have two options for call subcontrollers for a main controller:

  1. By creating the subcontroller in a method of the main controller

  2. By creating the subcontroller from a view.

Note

Option A is more flexible than Option B, especially if the sub-controller should be initialized once only in method DO_INIT.

Procedure

Option A

  • In method DO_INIT or DO_REQUEST, for example, add the following coding:

    ...
    
      data: addresscontroller type ref to CL_C_MYPROJ_ADDRESS.
    * create the controller
      addresscontroller ?= create_controller(
    
         controller_name = 'address.do'
         component_id = 'ad'
         ).
    
    * set some attributes with a self defined methods
      addresscontroller->Init_data( ... ).
    
    ...
    
                      

    or

    ...
    
      data: subcontroller type ref to CL_BSP_CONTROLLER2.
    * create the controller
      subcontroller ?= create_controller(
    
         controller_name = 'address.do'
         controller_id = 'ad'
         ).
    
    * set some attributes with standard method
      subcontroller->set_attributes( name = 'address' 
         value = ship_address ).
    
    
                      
  • Call the controller in the view.

    Two components are called in the above example: the address component ( address.do) and the flight component ( flights.do).

    COMPONENT_ID identifies the controller. In method CREATE_CONTROLLER this is the parameter COMPONENT_ID, and in <bsp:call> element this is the attribute COMP_ID:

    <%@page language="abap"%>
    <%@extension name="htmlb" prefix="htmlb"%>
    <%@extension name="bsp" prefix="bsp"%>
    
    
    <htmlb:content id="ComponentTest" >
      <htmlb:page title = "Component Test">
        <H1>Component Test</H1>
        <htmlb:form id="myFormId" method="post">
    
          <htmlb:tray id    = "tray1"
            title       = "Address"
            design      = "form"
            width       = "350"
            isCollapsed = "false" >
    
    
            <bsp:call url="address.do" comp_id="ad">
            </bsp:call>
          </htmlb:tray>
    
          <htmlb:tray id     = "tray2"
            title       = "Flights"
            design      = "form"
            width       = "350"
            isCollapsed = "false" >
          <bsp:call url="flights.do" comp_id="fl">
          </bsp:call>
      </p>
        <htmlb:button id="SAVE" text="SAVE DATA" onClick="SAVE" />
        <htmlb:button id="CANCEL" text="CANCEL" onClick="CANCEL" />
        </htmlb:form>
      </htmlb:page>
    </htmlb: content>
                      

Option B

In this option, you do not need to create the subcontroller in the coding of the main controller. Instead you should only add the parameters to the view call, which then creates and calls the controller. In the following example, ship_address is an attribute of the view and is set by the controller:

<%@page language="abap"%>
<%@extension name="htmlb" prefix="htmlb"%>
<%@extension name="bsp" prefix="bsp"%>

<htmlb:content id="ComponentTest" >
  <htmlb:page title = "Component Test">
    <H1>Component Test</H1>
    <htmlb:form id="myFormId" method="post">

      <htmlb:tray id    = "tray1"
        title       = "Address"
        design      = "form"
        width       = "350"
        isCollapsed = "false" >
        <bsp:call url="address.do" comp_id="ad">
          <bsp:parameter name="address" value="<%=ship_address%>"/>
        </bsp:call>
      </htmlb:tray>

      <htmlb:tray id     = "tray2"
        title       = "Flights"
        design      = "form"
        width       = "350"
        isCollapsed = "false" >
        <bsp:call url="flights.do" comp_id="fl">
        </bsp:call>
      </htmlb:tray>

    </p>
    <htmlb:button id="SAVE" text="SAVE DATA" onClick="SAVE" />
    <htmlb:button id="CANCEL" text="CANCEL" onClick="CANCEL" />
    </htmlb:form>
  </htmlb:page>
</htmlb:content>

            

Continue by Determining Input Processing.