If an action of a UI element is triggered on the user interface of a Web Dynpro application, the event handler of the view controller linked to this action is automatically called. In the event handler, the application developer adds the source code for the steps that will trigger the action. Examples for these steps:
· Reading, editing, and resetting context elements
· Calling function modules
· Triggering navigation
Programming
From a technical point of view, an event handler differs from other controller methods only in that it also responds to the event assigned to the event handler. For programming all controller methods, you can choose from several special classes with attributes and methods used to execute the processing steps specific to Web Dynpro. The following simple example describes in detail a possible structure of a controller method for the handling of an action. For further information on frequently used interfaces and their methods and attributes, refer to chapter Programming of Controller Methods. For a complete list of interfaces, refer to the reference section of this documentation.
First Example: Graphic Representation of a Simple Flight List
The user of a Web Dynpro application enters a value in the input field of a view (in this case the abbreviation of an airline). The user selects a button. The following table is to be displayed including the data that corresponds to the user input.
The graphic above shows the design scheme of the view layout and the corresponding context. When you call the application for the first time, the table is empty. Once the user enters the value and selects the button GO, the corresponding action GO is automatically triggered and the event handler method ONACTIONGO is called. The following steps must be performed in this method:
1. The attribute of the context node INPUT_NODE is read and passed to an internal variable of the method ONACTIONGO.
2. An internal table is filled according to the value of the internal variable.
3. The context node is filled with the content of the internal table.
How do these steps translate into source code in the method ONACTIONGO?
Data Declaration
method ONACTIONGO.
data: INPUT_NODE type ref to IF_WD_CONTEXT_NODE, TABLE_NODE type ref to IF_WD_CONTEXT_NODE,
CAR type STRING, FLIGHTS type standard table of SPFLI.
|
First, all of the required internal variables are declared:
· INPUT_NODE is declared as an internal variable for the context node of the user input
· TABLE_NODE is declared as an internal variable for the context node of the result table
· CAR is declared as an internal variable of the user input
· FLIGHTS is declared as an internal table for the result representation
In this example, the table FLIGHTS refers to the Dictionary table SPFLI and therefore does not need be declared in more detail.
Importing the User Input
The internal variable INPUT_NODE is bound to the context node INPUT_NODE:
INPUT_NODE = WD_CONTEXT->GET_CHILD_NODE( 'INPUT_NODE' ).
|
To do this, you use the attribute WD_CONTEXT and the method GET_CHILD_NODE of the interface IF_WD_CONTEXT_NODE which is available in the Web Dynpro framework.
The attribute WD_CONTEXT is always a reference to the local controller context: The method ONACTIONGO is a method of the current view controller. This means that WD_CONTEXT is the reference to the context of the current view in this case (see chapter Reference Variable WD_CONTEXT)
The method GET_CHILD_NODE returns the reference to the context node INPUT_NODE.
The method GET_ATTRIBUTE of the same interface subsequently reads the context attribute:
INPUT_NODE->GET_ATTRIBUTE( exporting Name = 'IN1' importing Value = CAR ).
|
This method retrieves the value of the attribute IN1 from the context node INPUT_NODE and passes it to the internal variable CAR.
This means that the value of the UI element Inputfield is passed to the method ONACTIONGO using the view context and can now be edited.
Filling the Result Table
The internal table FLIGHTS is filled using a formatted class which, in this example, is called CL_WD_FLIGHT_MODEL and contains the method GET_FLIGHTS_BY_CARRID. Variable CAR is passed to this method.
FLIGHTS = CL_WD_FLIGHT_MODEL=>GET_FLIGHTS_BY_CARRID( CAR ).
|
In this step, no elements specific to Web Dynpro are used.
Passing the Result Table
Once the internal table FLIGHTS is calculated, it must be linked to the context node TABLE_NODE. As for the reading of the input field, two steps are required:
TABLE_NODE = WD_CONTEXT->GET_CHILD_NODE( 'TABLE_NODE' ).
|
First, the context node TABLE_NODE of the view context is assigned to the internal variable TABLE_NODE. The required attribute or method has already been used for the linking of the node INPUT_NODE. Finally, the content of the internal table FLIGHTS is passed to the internal variable TABLE_NODE.
TABLE_NODE->BIND_ELEMENTS( FLIGHTS ).
endmethod.
|
The method bind_elements is also a method of the interface IF_WD_CONTEXT_NODE. It creates new elements from the internal table FLIGHTS and adds them to the internal variable TABLE_NODE. The attributes for the context node TABLE_NODE are now filled with the values of the internal table and the UI element Table can display the values in the view layout.
No comments:
Post a Comment