You are on page 1of 21

Controller and Context Programming

Contents:
The Context At Runtime Understand the controller methods that are available to you for application coding The Context API

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

The Context API: Topic Objectives

After completing this topic, you will be able to: Understand how to access nodes and attributes in the context using the context API.

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

Common Controller Features: Standard Controller Hook Methods Controller


Implementation Context
Root Node

Required Controllers Controller Interface

Other WD Controllers
Custom Controller

Standard Hook Methods Instance Methods

Business Logic (Models)

Component Usage

Other WD Components

Created by explicit declaration or coding


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

Created by the Web Dynpro Framework (WDF)

Standard Hook Methods for all controllers

method WDDOINIT. endmethod.

method WDDOEXIT. endmethod.

All controllers have these two standard hook methods. The method will only be called during the controllers lifecycle if they contain coding.

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

Common Controller Features: Controller Instance Methods Controller


Implementation Context
Root Node

Required Controllers Controller Interface

Other WD Controllers
Custom Controller

Standard Hook Methods Instance Methods

Business Logic (Models)

Component Usage

Other WD Components

Created by explicit declaration or coding


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

Created by the Web Dynpro Framework (WDF)

Controller Attributes and Utility methods


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

Arbitrary methods can be created - .

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 view controller). WD_THIS - self reference of the local interface, type depends on the controller type. WD_CONTEXT - reference to the context of associated controller.

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 methods and attributes. Attribute will automatically assigned to all view controllers when a view is created. For all other controller the WD_COMP_CONTROLLER attribute will be assigned, when the properties of the controller the component controller is used.
SAP AG 2005, Title of Presentation / Speaker Name / #

Standard Hook Methods Component Controller

WDDOBEFORENAVIGATION
It is executed before the navigation stack is processed

WDDOPOSTPROCESSING Data from multiple components can be validated before the next step is
execute

Note: Only a component controller has these hook methods.


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

Access to Attribute of Node Element I


Context Root
Default 0 Element

Flights
CARRID CONNID CARRID 2 CONNID CARRID 1 CONNID
..n

Note: Node and attribute names must be used in upper case

data: Node_Flights

type ref to If_Wd_Context_Node.

* navigate from <CONTEXT> to <FLIGHTS> via lead selection Node_Flights = wd_Context->get_Child_Node( Name = `FLIGHTS` ). * @TODO handle not set lead selection if ( Node_Flights is initial ). endif.

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

Access to Attribute of Node Element II


Context Root
Default 0 Element

Flights
CARRID CONNID CARRID 2 CONNID CARRID 1 CONNID
..n

data: Node_Flights Elem_Flights

type ref to If_Wd_Context_Node, type ref to If_Wd_Context_Element.

* navigate from <CONTEXT> to <FLIGHTS> via lead selection Node_Flights = wd_Context->get_Child_Node( Name = `FLIGHTS` ). * get element via lead selection Elem_Flights = Node_Flights->get_Element( * @TODO handle not set lead selection if ( Elem_Flights is initial ). endif.

).

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

Access to Attribute of Node Element III


Context Root
Default 0 Element

Flights
CARRID CONNID CARRID 2 CONNID CARRID 1 CONNID
..n

data: Node_Flights Elem_Flights Item_CARRID

type ref to If_Wd_Context_Node, type ref to If_Wd_Context_Element, like Stru_Flights-CARRID.

* navigate from <CONTEXT> to <FLIGHTS> via lead selection Node_Flights = wd_Context->get_Child_Node( Name = `FLIGHTS` ). * get element via lead selection Elem_Flights = Node_Flights->get_Element(

).

* get single attribute Elem_Flights->get_Attribute( exporting Name = `CARRID` importing Value = Item_Carrid ).
SAP AG 2005, Title of Presentation / Speaker Name / #

Access to all Static Attributes of a Node Element


Context Root
Default 0 Element

Flights
CARRID CONNID CARRID 2 CONNID CARRID 1 CONNID
..n

data: Node_Flights Elem_Flights Stru_Flights

type ref to If_Wd_Context_Node, type ref to If_Wd_Context_Element, type If_Componentcontroller=>Element_Flights.

* navigate from <CONTEXT> to <FLIGHTS> via lead selection Node_Flights = wd_Context->get_Child_Node( Name = `FLIGHTS` ). * get element via lead selection Elem_Flights = Node_Flights->get_Element(

).

* get all declared attributes Elem_Flights->get_Static_Attributes( importing Static_Attributes = Stru_Flights ).

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

Access to all Elements of a Node


Context Root
Default 0 Element

Flights
CARRID CONNID CARRID 2 CONNID CARRID 1 CONNID
..n

Itab

data: Node_Flights Elem_Flights lt_Flights

type ref to If_Wd_Context_Node, type ref to If_Wd_Context_Element, type If_Main_View=>Elements_Flights .

* navigate from <CONTEXT> to <FLIGHTS> via lead selection Node_Flights = wd_Context->get_Child_Node( Name = `FLIGHTS` ). * @TODO handle not set lead selection if ( Node_Flights is initial ). endif. * get all node element Node_Flights->GET_STATIC_ATTRIBUTES_TABLE( importing table = lt_Flights ).

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

Binding of an Element to a Node I


Context Root
Default 0 Element

FLIGHTS

data: Node_Flights type ref to If_Wd_Context_Node.

* navigate from <CONTEXT> to <FLIGHTS> via lead selection node_flights = wd_context->get_child_node( Name = 'FLIGHTS' ).

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

Binding of an Element to a Node II


Context Root
Default 0 Element

FLIGHTS

data: Node_Flights type ref to If_Wd_Context_Node, First_flight_Elem type ref to If_Wd_Context_Element. * navigate from <CONTEXT> to <FLIGHTS> via lead selection node_flights = wd_context->get_child_node( Name = 'FLIGHTS' ). * create new element for node FLIGHTS First_flight_Elem = Node_Flights->create_element(

).

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

Binding of an Element to a Node III


Context Root
Default 0 Element

FLIGHTS

CARRID

CONNID

data: Node_Flights type ref to If_Wd_Context_Node, First_flight_Elem type ref to If_Wd_Context_Element. * navigate from <CONTEXT> to <FLIGHTS> via lead selection node_flights = wd_context->get_child_node( Name = 'FLIGHTS' ). * create new element for node FLIGHTS First_flight_Elem = Node_Flights->create_element(

).

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

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

Binding of an Element to a Node IV


Context Root
Default 0 Element

FLIGHTS

CARRID CONNID

data: Node_Flights type ref to If_Wd_Context_Node, First_flight_Elem type ref to If_Wd_Context_Element. * navigate from <CONTEXT> to <FLIGHTS> via lead selection node_flights = wd_context->get_child_node( Name = 'FLIGHTS' ). * create new element for node FLIGHTS First_flight_Elem = Node_Flights->create_element(

).

* set attributes First_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_Elem SET_INITIAL_ELEMENTS = abap_false ). 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 <CONTEXT> to <FLIGHTS> via lead selection node_flights = wd_context->get_child_node( Name = 'FLIGHTS' ).

* set values to node->attributes Stru_flights-carrid = 'AA'. Stru_flights-connid = '017'. * bind new element to node Node_flights->bind_structure( new_item = Stru_flights SET_INITIAL_ELEMENTS = abap_false ).

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

Binding of a Table to a Node


Context Root
Default 0 Element

FLIGHTS
CARRID
CARRID CONNID
1

Itab

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 table Stru_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 reference Node_Flights = wd_context->get_child_node( 'FLIGHTS' ). * bind local table Node_Flights->bind_table( lt_flights ). SAP AG 2005, Title of Presentation / Speaker Name / #

Controller and Context Programming: Unit Summary

You should now be able to: Understand how to access nodes and attributes in the context using the context API

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

You might also like