controller and context programming

Embed Size (px)

Citation preview

  • 7/29/2019 controller and context programming

    1/21

    SAP AG 2005, Title of Presentation / Speaker Name / #

    The Context At Runtime

    Understand the controller methods that are availableto you for application coding

    The Context API

    Contents:

    Controller and Context Programming

  • 7/29/2019 controller and context programming

    2/21

    SAP AG 2005, Title of Presentation / Speaker Name / #

    After completing this topic, you will be able to:

    Understand how to access nodes and attributes inthe context using the context API.

    The Context API: Topic Objectives

  • 7/29/2019 controller and context programming

    3/21

    SAP AG 2005, Title of Presentation / Speaker Name / #

    Common Controller Features:Standard Controller Hook Methods

    Controller

    Implementation

    StandardHook

    Methods

    Instance

    Methods

    Context

    Root Node

    RequiredControllers

    ControllerInterface

    Other WDControllers

    CustomController

    BusinessLogic

    (Models)

    Created by explicit declaration or coding Created by the Web Dynpro Framework (WDF)

    ComponentUsage

    Other WDComponents

  • 7/29/2019 controller and context programming

    4/21

    SAP AG 2005, Title of Presentation / Speaker Name / #

    Standard Hook Methods for all controllers

    All controllers have these two standard hook methods.

    The method will only be called during the controllers lifecycle if theycontain coding.

    method WDDOINIT.endmethod.

    method WDDOEXIT.endmethod.

  • 7/29/2019 controller and context programming

    5/21

    SAP AG 2005, Title of Presentation / Speaker Name / #

    Common Controller Features: Controller Instance Methods

    Controller

    Implementation

    StandardHook

    Methods

    Instance

    Methods

    Context

    Root Node

    RequiredControllers

    ControllerInterface

    Other WDControllers

    CustomController

    BusinessLogic

    (Models)

    Created by explicit declaration or coding Created by the Web Dynpro Framework (WDF)

    ComponentUsage

    Other WDComponents

  • 7/29/2019 controller and context programming

    6/21

    SAP AG 2005, Title of Presentation / Speaker Name / #

    Controller Attributes and Utility methods

    Attributes for the controller can be created (public or private)

    Arbitrary methods can be created - .

  • 7/29/2019 controller and context programming

    7/21 SAP AG 2005, Title of Presentation / Speaker Name / #

    Standard Controller Attributes WD_CONTEXT and WD_THIS

    WD_CONTEXT and WD_THIS

    present in any WD controller (excepted interface and interface viewcontroller).

    WD_THIS - self reference of the local interface, type depends on the

    controller type. WD_CONTEXT - reference to the context of associated controller.

  • 7/29/2019 controller and context programming

    8/21 SAP AG 2005, Title of Presentation / Speaker Name / #

    Standard Controller Attribute WD_COMP_CONTROLLER

    WD_COMP_CONTROLLER

    present in any WD controller.

    reference to the component controller with access to all public methodsand attributes.

    Attribute will automatically assigned to all view controllers when a viewis created.

    For all other controller the WD_COMP_CONTROLLER attribute willbe assigned, when the properties of the controller the componentcontroller is used.

  • 7/29/2019 controller and context programming

    9/21 SAP AG 2005, Title of Presentation / Speaker Name / #

    Standard Hook Methods Component Controller

    Note: Only a component controller has these hook methods.

    WDDOBEFORENAVIGATIONIt is executed before the navigation stack is processed

    WDDOPOSTPROCESSING

    Data from multiple components can be validated before the next step isexecute

  • 7/29/2019 controller and context programming

    10/21 SAP AG 2005, Title of Presentation / Speaker Name / #

    Access to Attribute of Node Element I

    Flights..nCARRID

    CONNID2CARRID

    CONNID1CARRID

    CONNID

    Context Root

    0Default

    Element

    data: Node_Flights type ref to If_Wd_Context_Node.

    * navigate from to via lead selectionNode_Flights = wd_Context->get_Child_Node( Name = `FLIGHTS` ).

    * @TODO handle not set lead selectionif ( Node_Flights is initial ).endif.

    Note: Node and attribute

    names must beused in upper case

  • 7/29/2019 controller and context programming

    11/21 SAP AG 2005, Title of Presentation / Speaker Name / #

    Access to Attribute of Node Element II

    Flights..nCARRID

    CONNID2CARRID

    CONNID1CARRID

    CONNID

    Context Root

    0Default

    Element

    data: Node_Flights type ref to If_Wd_Context_Node,Elem_Flights type ref to If_Wd_Context_Element.

    * navigate from to via lead selectionNode_Flights = wd_Context->get_Child_Node( Name = `FLIGHTS` ).

    * get element via lead selectionElem_Flights = Node_Flights->get_Element( ).

    * @TODO handle not set lead selectionif ( Elem_Flights is initial ).endif.

  • 7/29/2019 controller and context programming

    12/21 SAP AG 2005, Title of Presentation / Speaker Name / #

    Access to Attribute of Node Element III

    Flights..nCARRID

    CONNID2CARRID

    CONNID1CARRID

    CONNID

    Context Root

    0Default

    Element

    data: Node_Flights type ref to If_Wd_Context_Node,Elem_Flights type ref to If_Wd_Context_Element,Item_CARRID like Stru_Flights-CARRID.

    * navigate from to via lead selectionNode_Flights = wd_Context->get_Child_Node( Name = `FLIGHTS` ).

    * get element via lead selection

    Elem_Flights = Node_Flights->get_Element( ).

    * get single attributeElem_Flights->get_Attribute(exportingName = `CARRID`importing

    Value = Item_Carrid ).

  • 7/29/2019 controller and context programming

    13/21 SAP AG 2005, Title of Presentation / Speaker Name / #

    Access to all Static Attributes of a Node Element

    Flights..nCARRID

    CONNID2CARRID

    CONNID1CARRID

    CONNID

    Context Root

    0Default

    Element

    data: Node_Flights type ref to If_Wd_Context_Node,Elem_Flights type ref to If_Wd_Context_Element,Stru_Flights type If_Componentcontroller=>Element_Flights.

    * navigate from to via lead selectionNode_Flights = wd_Context->get_Child_Node( Name = `FLIGHTS` ).

    * get element via lead selection

    Elem_Flights = Node_Flights->get_Element( ).

    * get all declared attributesElem_Flights->get_Static_Attributes(importingStatic_Attributes = Stru_Flights ).

  • 7/29/2019 controller and context programming

    14/21 SAP AG 2005, Title of Presentation / Speaker Name / #

    Access to all Elements of a Node

    Flights..nCARRID

    CONNID2CARRID

    CONNID1CARRID

    CONNID

    Context Root

    0Default

    Element

    data: Node_Flights type ref to If_Wd_Context_Node,Elem_Flights type ref to If_Wd_Context_Element,lt_Flights type If_Main_View=>Elements_Flights .

    * navigate from to via lead selectionNode_Flights = wd_Context->get_Child_Node( Name = `FLIGHTS` ).

    * @TODO handle not set lead selection

    if ( Node_Flights is initial ).endif.

    * get all node elementNode_Flights->GET_STATIC_ATTRIBUTES_TABLE( importingtable = lt_Flights ).

    Itab

  • 7/29/2019 controller and context programming

    15/21 SAP AG 2005, Title of Presentation / Speaker Name / #

    Binding of an Element to a Node I

    FLIGHTSContext Root

    0Default

    Element

    data:Node_Flights type ref to If_Wd_Context_Node.

    * navigate from to via lead selectionnode_flights = wd_context->get_child_node( Name = 'FLIGHTS' ).

  • 7/29/2019 controller and context programming

    16/21 SAP AG 2005, Title of Presentation / Speaker Name / #

    Binding of an Element to a Node II

    FLIGHTSContext Root

    0Default

    Element

    data:Node_Flights type ref to If_Wd_Context_Node,First_flight_Elem type ref to If_Wd_Context_Element.

    * navigate from to via lead selectionnode_flights = wd_context->get_child_node( Name = 'FLIGHTS' ).

    * create new element for node FLIGHTS

    First_flight_Elem = Node_Flights->create_element( ).

  • 7/29/2019 controller and context programming

    17/21

    SAP AG 2005, Title of Presentation / Speaker Name / #

    Binding of an Element to a Node III

    FLIGHTSContext Root

    0Default

    Element

    CARRID

    CONNID

    data:Node_Flights type ref to If_Wd_Context_Node,First_flight_Elem type ref to If_Wd_Context_Element.

    * navigate from to via lead selectionnode_flights = wd_context->get_child_node( Name = 'FLIGHTS' ).

    * create new element for node FLIGHTS

    First_flight_Elem = Node_Flights->create_element( ).

    * set attributesFirst_flight_Elem->set_attribute( name = 'CARRID' value = 'LH' ).First_flight_Elem->set_attribute( name = 'CONNID' value = '400' ).

  • 7/29/2019 controller and context programming

    18/21

    SAP AG 2005, Title of Presentation / Speaker Name / #

    FLIGHTSContext Root

    0Default

    Element

    CARRID

    CONNID

    1

    Binding of an Element to a Node IV

    data:Node_Flights type ref to If_Wd_Context_Node,First_flight_Elem type ref to If_Wd_Context_Element.

    * navigate from to via lead selectionnode_flights = wd_context->get_child_node( Name = 'FLIGHTS' ).

    * create new element for node FLIGHTSFirst_flight_Elem = Node_Flights->create_element( ).

    * set attributesFirst_flight_Elem->set_attribute( name = 'CARRID' value = 'LH' ).First_flight_Elem->set_attribute( name = 'CONNID' value = '400' ).

    * bind first element to node

    Node_Flights->bind_element( new_item = First_flight_ElemSET_INITIAL_ELEMENTS = abap_false ).

  • 7/29/2019 controller and context programming

    19/21

    SAP AG 2005, Title of Presentation / Speaker Name / #

    Static Attributes and Binding of a Element to a Node

    data:Node_Flights type ref to If_Wd_Context_Node,Stru_flights type If_Componentcontroller=>Element_flights.

    * navigate from to via lead selectionnode_flights = wd_context->get_child_node( Name = 'FLIGHTS' ).

    * set values to node->attributesStru_flights-carrid = 'AA'.Stru_flights-connid = '017'.

    * bind new element to nodeNode_flights->bind_structure( new_item = Stru_flights

    SET_INITIAL_ELEMENTS = abap_false ).

  • 7/29/2019 controller and context programming

    20/21

    SAP AG 2005, Title of Presentation / Speaker Name / #

    FLIGHTSContext Root

    0Default

    Element

    Binding of a Table to a Node

    data:Node_Flights type ref to If_Wd_Context_Node,

    lt_flights type If_Componentcontroller=>Elements_flights,Stru_flights like line of lt_flights.

    * append values to local tableStru_flights-carrid = 'LH'.Stru_flights-connid = '400'.append Stru_flights to lt_flights.

    Stru_flights-carrid = 'AA'.Stru_flights-connid = '017'.append Stru_flights to lt_flights.

    * get node referenceNode_Flights = wd_context->get_child_node( 'FLIGHTS' ).

    * bind local tableNode_Flights->bind_table( lt_flights ).

    CARRID

    CONNID

    1

    ItabCARRID

  • 7/29/2019 controller and context programming

    21/21

    SAP AG 2005 Titl f P t ti / S k N / #

    You should now be able to:

    Understand how to access nodes and attributes inthe context using the context API

    Controller and Context Programming: Unit Summary