Anda di halaman 1dari 19

Controller and Context Programming

Page 1

Protection notice / Copyright Siemens AG 2007. All rights reserved.

Standard Controller Hook Methods


Controller
Implementation
Context
Root Node

Standard
Hook
Methods

Required
Controllers
Controller
Interface

Component
Usage

Page 2

Custom
Controller

Business
Logic
(Models)

Instance
Methods

Created by explicit declaration or coding

Other WD
Controllers

Other WD
Components

Created by the Web Dynpro Framework (WDF)

Protection notice / Copyright Siemens AG 2007. All rights reserved.

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.
Page 3

Protection notice / Copyright Siemens AG 2007. All rights reserved.

Controller Instance Methods


Controller
Implementation
Context
Root Node

Standard
Hook
Methods
Instance
Methods

Required
Controllers

Other WD
Controllers
Custom
Controller

Controller
Interface
Business
Logic
(Models)
Component
Usage
Other WD
Components

Created by explicit declaration or coding

Page 4

Created by the Web Dynpro Framework (WDF)

Protection notice / Copyright Siemens AG 2007. All rights reserved.

Controller Attributes and Utility methods


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

Arbitrary methods can be created - .

Page 5

Protection notice / Copyright Siemens AG 2007. All rights reserved.

Standard Controller Attributes


WD_CONTEXT and WD_THIS

WD_CONTEXT and WD_THIS


present in any WD controller (except 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.

Page 6

Protection notice / Copyright Siemens AG 2007. All rights reserved.

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.
Page 7

Protection notice / Copyright Siemens AG 2007. All rights reserved.

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.

Page 8

Protection notice / Copyright Siemens AG 2007. All rights reserved.

Access to Attribute of Node Element I


Context Root
Default 0
Element

Flights

CARRID
CARRID
2
CONNID
CARRID
CONNID
1

..n

Note: Node and attribute


names must be
used in upper case

CONNID

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.

Page 9

Protection notice / Copyright Siemens AG 2007. All rights reserved.

Access to Attribute of Node Element II


Context Root
Default 0
Element

Flights

CARRID
CARRID 2
CONNID
CARRID
CONNID
1

..n

CONNID

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.

Page 10

Protection notice / Copyright Siemens AG 2007. All rights reserved.

Access to Attribute of Node Element III


Context Root
Default 0
Element

Flights
CARRID
CARRID
2
CONNID
CARRID
CONNID 1

..n

CONNID

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 ).
Page 11

Protection notice / Copyright Siemens AG 2007. All rights reserved.

Access to all Static Attributes of a


Node Element
Context Root
Default 0
Element

Flights

CARRID
CONNID
CARRID
2

..n

CARRID
CONNID
1
CONNID

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 ).

Page 12

Protection notice / Copyright Siemens AG 2007. All rights reserved.

Access to all Elements of a Node


Context Root
Default 0
Element

Flights

CARRID
CARRID
CONNID
2

..n

Itab

CONNID
CARRID
1
CONNID

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 ).

Page 13

Protection notice / Copyright Siemens AG 2007. All rights reserved.

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' ).

Page 14

Protection notice / Copyright Siemens AG 2007. All rights reserved.

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(

Page 15

).

Protection notice / Copyright Siemens AG 2007. All rights reserved.

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' ).
Page 16

Protection notice / Copyright Siemens AG 2007. All rights reserved.

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
).
Protection
notice / Copyright Siemens AG 2007. All rights reserved.
Page
17

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 ).

Page 18

Protection notice / Copyright Siemens AG 2007. All rights reserved.

Binding of a Table to a Node


Context Root
Default 0
Element

FLIGHTS
CARRID

Itab
1

CONNID

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
lt_flights
notice).
/ Copyright Siemens AG 2007. All rights reserved.
Page 19Node_Flights->bind_table( Protection

Anda mungkin juga menyukai