A number of predefined methods are provided by the controller. These methods, which are called by the Web Dynpro runtime in a predefined order, are calledhook methods.
As these methods are empty at the time of controller creation, the developer can write any desired code in it.
The developer can also define additional methods, such as ordinary methods, event-handler methods, or supply functions.
STANDARD HOOK METHODS FOR ALL CONTROLLERS
This slide depicts the two standard hook methods that exist for all controller types:
WDDOINIT( ) is the first method processed in the controller’s lifetime. It is called once in the controller’s lifecycle, immediately after the controller is instantiated. Therefore, you enter all your initialization codes here.
WDDOEXIT( ) is the last method processed. As it marks the end of a controller’s lifecycle, you can mention all your cleanup codes here.
STANDARD HOOK METHODS: COMPONENT
Additional hook methods are available, depending on the controller type.
WDDOBEFORENAVIGATION( ) is called after the action method is processed and just before the events in the navigation queue are processed by the Web Dynpro framework.
WDDOPOSTPROCESSING( ) is the last controller method that is processed before the UI is sent to the client.
WDDOAPPLICATIONSTATECHANGE( ) is processed each time the application is suspended or resumed. You can suspend a Web Dynpro application by firing a suspend plug of the window. The suspended Web Dynpro application can be resumed by a resume plug.
STANDARD HOOK METHODS: VIEW CONTROLLER
View controllers have access to four additional hook methods:
WDDOBEFOREACTION( ) is the first method processed in the Web Dynpro application after you raise a client event bound to an action. It contains a reference to the source code related to input checks.
WDDOAFTERACTION( ) is called after an action handler method is processed. It modularizes the source code related to action handling.
WDDOMODIFYVIEW( ) helps you access the UI element hierarchy and can be used to dynamically manipulate the latter. It is the last view controller method to be processed.
WDDOONCONTEXTMENU( ) is processed each time you right-click any UI element defined in the related view layout.
PHASE MODEL (SIMPLE CASE)
Controller methods are processed in a certain order, which is described in the phase model:
When starting a Web Dynpro application (Application start),
the method WDDOINIT( ) instantiates all controllers needed for the first display;
the inbound plug method HANDLEDEFAULT( ) processes the interface view related to the application; and
the component controller methods WDDOBEFORENAVIGATION( ) and WDDOPOSTPROCESSING( ), and the view controller method WDDOMODIFYVIEW( ), are all processed accordingly.The phase model for a request triggered by a user interaction describes the action handler method, inbound plug handler method, and component and view controller methods (Navigation to view):
WDDOBEFOREACTION( ), ONACTION<ACTION>( ) and WDDOAFTERACTION( ) are processed if the client side event is bound to an action.
The component controller method WDDOBEFORENAVIGATION( ) is processed.
The inbound plug method Handle<PLUG>( ) is processed if
an outbound plug is fired;
a navigation link to an inbound plug is defined; and
the view related to the inbound plug is instantiated by processing the method WDDOINIT( ).The method WDDOEXIT( ) is processed if the life time of the previous view is restricted.
The view controller method WDDOMODIFYVIEW( ) is processed for the next View.
Finally, the component controller method WDDOPOSTPROCESSING( ) is processed.
When starting a Web Dynpro application (Application start),
the method WDDOINIT( ) instantiates all controllers needed for the first display;
the inbound plug method HANDLEDEFAULT( ) processes the interface view related to the application; and
the component controller methods WDDOBEFORENAVIGATION( ) and WDDOPOSTPROCESSING( ), and the view controller method WDDOMODIFYVIEW( ), are all processed accordingly.The phase model for a request triggered by a user interaction describes the action handler method, inbound plug handler method, and component and view controller methods (Navigation to view):
WDDOBEFOREACTION( ), ONACTION<ACTION>( ) and WDDOAFTERACTION( ) are processed if the client side event is bound to an action.
The component controller method WDDOBEFORENAVIGATION( ) is processed.
The inbound plug method Handle<PLUG>( ) is processed if
an outbound plug is fired;
a navigation link to an inbound plug is defined; and
the view related to the inbound plug is instantiated by processing the method WDDOINIT( ).The method WDDOEXIT( ) is processed if the life time of the previous view is restricted.
The view controller method WDDOMODIFYVIEW( ) is processed for the next View.
Finally, the component controller method WDDOPOSTPROCESSING( ) is processed.
ADDITIONAL CONTROLLER METHODS
You can create additional methods by
declaring the method name and its parameters on the Methods tab of the controller editor window;
choosing Method Type as Method to define an ordinary method;
choosing the Method Type as Event Handler to create an event handler method, which can be registered statically (in the Event column) to any event fired in a controller; or
choosing the Method Type as Supply Function to define methods that can be bound to context nodes (Supply Function property).
These methods are automatically called from the Web Dynpro framework if the node is accessed and it is marked as invalid.
You can set the Interface flag for a user-defined component controller method so that the method is also visible to other components.
STANDARD CONTROLLER ATTRIBUTES
Each controller has at least two predefined attributes.
The standard attributes are
WD_THIS, which is a reference to the current controller’s interface IF_<controller name> and all the functionality implemented in the generated class;
WD_CONTEXT, which is a reference to the controller’s context root node or the starting point for access to the controller’s context; and
WD_COMP_CONTROLLER, which is a reference to the component controller and provides access to all the methods and public attributes of the latter.
USER-DEFINED CONTROLLER ATTRIBUTES AND CONTROLLER METHODS
You can define additional attributes for the related controller on the Attributes tab.
These attributes are also visible for other controllers of the same Web Dynpro component if the Public flag is set.
Attributes cannot be exposed to the component’s interface.
ACCESSING A CONTEXT NODE
A local interface is generated with the name IF_<ctrl> for each controller.
A constant (WDCTX_<node>) is generated in this interface for each node <node> of a controller context.
A standard attribute WD_CONTEXT is used to access the context root node.
The get_child_node( ) method is used to identify the child nodes of the context root nodes.
ACCESSING THE NODE ELEMENT AT LEAD SELECTION
You can use the method get_element( ) for reference to the element at lead selection of the context node being accessed. This method returns a reference to the element instance of type IF_WD_CONTEXT_ELEMENT.
ACCESSING CONTEXT NODES AND NODE ELEMENTS
To identify the child nodes of the context root nodes, use the method get_child_node( ).
To access the element with index n, use the method get_element(index= n).
To obtain the number of elements in a collection, use the method get_element_count( ).
ACCESSING A SINGLE ATTRIBUTE OF A NODE ELEMENT
You can use the method get_attribute( ) to access any attribute of a node element.
The name of the attribute must be exported and the import parameter returns the attribute value.
ACCESSING ALL STATICALLY DEFINED ATTRIBUTES OF A NODE ELEMENT
You can use the method get_static_attributes( ) to obtain statically defined attributes. A structure is returned in an import parameter.
ACCESS TO THE STATIC ATTRIBUTES OF ALL NODE ELEMENTS
You can use the method get_static_attributes_table( ) to retrieve the attributes of all elements as an internal table.
CHANGING A SINGLE ATTRIBUTE OF A NODE ELEMENT
You can use the method set_attribute( ) to change the value of any attribute of the node element.
CHANGING MULTIPLE ATTRIBUTES OF A NODE ELEMENT
The method set_static_attributes( ) can be used to change multiple attributes that are statically defined.
ACCESSING AND CHANGING ATTRIBUTES: CONTROLLER NODE
You can use the method get_attribute( ) to access any attribute of a node element. The name of the attribute must be exported and the import parameter returns the attribute value.
You can use the method get_static_attributes( ) to obtain statically defined attributes. A structure is returned in an import parameter.
You can use the method get_static_attributes_table( ) to retrieve the attributes of all elements as an internal table.
You can use the method set_attribute( ) to change the value of any attribute of the node element.
The method set_static_attributes( ) can be used to change multiple attributes that are statically defined.
GETTING THE REFERENCE TO A CONTEXT NODE
You can create an element that can be added to a certain context node. The reference to this node is determined by using the get_child_node( ) method of the standard attribute WD_CONTEXT, which points to the context root node.
CREATING A NEW NODE ELEMENT
You can use the method create_element( ) to create the new element, once you obtain the reference to the node.
SETTING THE ATTRIBUTE VALUES OF THE NEW ELEMENT
The attribute values can be defined using the setter methods set_attribute( ) or set_static_attributes( ).Initial values for the static attributes can be set using thestatic_attribute_values parameter.
BINDING AN ELMENT TO A CONTEXT NODE
The method bind_element( ), related to the node reference, helps you to finally add an element (not yet part of the context node) to the node.
This method has two import parameters:
The element reference is submitted through the parameter new_item.
The parameter set_initial_elements defines whether the new element is simply added to the element collection (value = abap_false) or replaces all existing elements in the collection (value = abap_true).
BINDING A STRUCTURE TO A CONTEXT NODE
You can use method bind_structure( ) with parameter new_item to bind a structure. The existing collection can be extended or replaced by using the parameterset_initial_elements.
BINDING AN INTERNAL TABLE TO A CONTEXT NODE
You can use the method bind_table( ) with parameter new_item to bind an internal table. You can use the parameter set_initial_elements to extend or replace the existing collection.
ADDING/DELETING ELEMENTS: CONTEXT NODE
You can use the method create_element( ) to create the new element once the reference to the node is obtained.
You can use the method bind_element( ) related to the node reference to add an element to the node.
You can use method bind_structure( ) with the parameter new_item to bind a structure. The existing collection can be extended or replaced by using the parameter set_initial_elements.
You can use method bind_table( ) with the parameter new_item to bind an internal table. The existing collection can be extended or replaced by using the parameter set_initial_elements.
You can use the method remove_element() to remove an element from the collection.
No comments:
Post a Comment