Dynamic Runtime Modifs Webdynpro
Dynamic Runtime Modifs Webdynpro
Contents:
Introduction Modifying the context structure at runtime Modifying the UI Element hierarchy at runtime The use of dynamic actions
After completing this unit, you will be able to: Understand what is dynamic programming
Under what circumstances should I write coding that performs dynamic modifications?
There are several situations in which type of coding could be required: When the structure of your data is not known until runtime When you want the behaviour of a screen to be generic and therefore dynamic When you are writing utility components that must function in a generic manner Etc
Coding steps:
Obtain a reference to the metadata of the context node that will act as the new nodes parent. In this case, we are creating an independent node, therefore we get a reference to the metadata of the root node. Call static method create_nodeinfo_from_struct( ) from helper class cl_wd_dynamic_tool A DDIC Structure can be used for the attribute creation.
BOOKID
CUSTOMID CLASS
PASSNAME
CARRID CONNID
Structure SBOOK DATA: dyn_node type ref to if_wd_context_node, FLDATE dyn_node_info TYPE REF TO if_wd_context_node_info, PRICE node_name TYPE string value 'FLIGHTS', . . . * navigate from <CONTEXT> to <FLIGHTS> via lead selection dyn_node = wd_Context->get_Child_Node( Name = node_name ). dyn_node_info = dyn_node->get_node_info( ).
* create sub node named BOOKINGS of sbook cl_wd_dynamic_tool=>create_nodeinfo_from_struct( parent_info = dyn_node_info node_name = 'BOOKINGS' structure_name = 'SBOOK' is_multiple = abap_true is_mandatory = abap_false ).
SAP AG 2005, Title of Presentation / Speaker Name / #
* add context attribute to node data: Ui_Attributes_info type ref to If_Wd_Context_Node_info. data: ls_att type WDR_CONTEXT_ATTRIBUTE_INFO. * get node info of context Ui_Attributes_info = Node_Ui_Attributes->get_node_info( ). ls_att-name ls_att-TYPE_NAME = = `TEXT_VISIBILITY`. 'WDUI_VISIBILITY'.
Only a view controller has these hook methods. The method WDDOMODIFYVIEW will only be called if: The view is part of the current view assembly and this is the first time the view is required, or The view is part of the current view assembly and an action belonging to the same view controller has been processed.
Context Metadata
CONNIDLabel
CONNIDInput FLDATELabel
FLDATEInput
PRICELabel PRICEInput
Coding steps:
Check that this is the first time the view has been rendered Obtain a reference to the root UI element container
method WDDOMODIFYVIEW . data: wd_container type ref to cl_wd_uielement_container, . . . * Check if first time check first_time = abap_true. wd_container ?= view->get_element( 'ROOTUIELEMENTCONTAINER' ).
Context Metadata
Coding steps:
Create a new InputField UI element object (bind to context attribute Create a new Label UI element object
InputField
InputField
Label
* Create label and input field ** create a input field wd_input_field = cl_wd_input_field=>new_input_field( view = view bind_value = 'CONNECTIONS.CARRID'). ** create a label for the input field wd_label = cl_wd_label=>new_label( label_for = wd_input_field->id ).
Dynamic Actions
Certain UI elements can trigger client-side events (e.g. pressing enter in an InputField, toggling a CheckBox or selecting the row of a table). In order for the client-side event to trigger the execution of a serverside method, Web Dynpro uses the concept of Actions.
Actions can either be assigned declaratively to UI element events at design time, or dynamically at runtime.
Actions assigned dynamically can only refer to existing server-side action handler methods. It is not possible to define the coding of an action event handler dynamically; only to define which existing action handler will be called when a client-side event is trapped.
Action Declaration
Declared action
Context Metadata
Context Root Connections CARRID CONNID FLDATE PRICE
Coding steps:
Create a new Button UI element object (assign an predefined action) Set the Button properties as required
* Create button ** create button UI element wd_button = cl_wd_button=>new_button( text = 'Show Flights' on_action = 'SELECT_FLIGHTS' ). ** set matrix_head_data for the label cl_wd_matrix_head_data=>new_matrix_head_data( element = wd_button ). ** add button to container wd_container->add_child( wd_button ).
SAP AG 2005, Title of Presentation / Speaker Name / #
Development Principle
Only if the required functionality of your application does not permit design time declarations, then use a dynamic modification approach.
All context node/attribute and UI elements which can be created during design time should be created during design time.
* get node info of context root node rootnode_info = wd_context->get_node_info( ). * Get the name of the table to be created tabname_node = wd_context->get_child_node( name = 'TABLE_DATA' ). tabname_node->get_attribute( EXPORTING name = 'NAME' IMPORTING value = tablename ). translate tablename to upper case. * create sub node of structure (tablename) cl_wd_dynamic_tool=>create_nodeinfo_from_struct( parent_info = rootnode_info node_name = tablename structure_name = tablename is_multiple = abap_true ).
SAP AG 2005, Title of Presentation / Speaker Name / #
* create new UI element table new_tab = cl_wd_dynamic_tool=>create_table_from_node( ui_parent = group_1 table_id = 'TESTTAB' node = dyn_node ).
** fill context node with data * create internal table of (tabletype) CREATE DATA stru_tab TYPE TABLE OF (tablename). ASSIGN stru_tab->* TO <tab>.
* Get table content SELECT * FROM (tablename) INTO CORRESPONDING FIELDS OF TABLE <tab>. * Bind internal table to context node dyn_node->bind_table( <tab> ).
SAP AG 2005, Title of Presentation / Speaker Name / #