4
Context Skip to end of metadata Added by Heidi Geisau , last edited by Bret Halford on Mar 17, 2014 (view change ) show comment Go to start of metadata Frequently Asked Questions - Context Issues This section of the FAQ provides answers to questions about the Web Dynpro context. What Can I Do If I Have Context Problems? How do I read user input (e.g. inputfields) from context? How do I get all selected elements of a context node? How can I select elements of a node program controlled? How can I dynamically create a context node during runtime? What Can I Do If I Have Context Problems? Go ahead as described in SAP note 999992 . back to top How do I read user input (e.g. inputfields) from context? You created a view with several input fields and you want to get the entered values for processing (e.g. save to database). Add a button UIElement to your view. In the properties tab of the button add a handler for the onAction event. Go to the action handler method you just created. Now you can use the wizard to automatically create the method calls to read the data from context.

Context Node

Embed Size (px)

DESCRIPTION

Content _node Details

Citation preview

ContextSkip to end of metadata Added byHeidi Geisau, last edited byBret Halfordon Mar 17, 2014(view change) show commentGo to start of metadataFrequently Asked Questions - Context IssuesThis section of the FAQ provides answers to questions about the Web Dynpro context.

What Can I Do If I Have Context Problems?How do I read user input (e.g. inputfields) from context?How do I get all selected elements of a context node?How can I select elements of a node program controlled?How can I dynamically create a context node during runtime?

What Can I Do If I Have Context Problems?Go ahead as described in SAP note999992.back to topHow do I read user input (e.g. inputfields) from context?You created a view with several input fields and you want to get the entered values for processing(e.g. save to database).Add a button UIElement to your view. In the properties tab of the button add a handler for theonAction event. Go to the action handler method you just created. Now you can use the wizard toautomatically create the method calls to read the data from context.

As example consider the following context structure: node_for_inputfields (cardinality 1:1) attribute_name (type String) attribute_text (type String)Both attributes are bound to the inputfields of the view.After using the wizard in the action handler method the necessary code will look as follows:data:Node_Node_For_inputfields type ref to If_Wd_Context_Node,Elem_Node_For_inputfields type ref to If_Wd_Context_Node,Stru_Node_For_inputfields Wd_This->Element_Txe_Barcodes.Node_Node_For_inputfields = wd_context->get_child_node( name = if_v_viewname=>wdctx_Node_For_inputfields ).Elem_Node_For_inputfields = Node_Node_For_inputfields->get_element( ).

Elem_Node_For_inputfields->get_static_attributes( IMPORTING static_attributes = Stru_Node_For_inputfields ).* Place code for processing entered values here

Stru_Node_For_inputfields is the structure of the context node and can be handled as normal structure to process the entered values.back to topHow do I get all selected elements of a context node?data:lr_context_node type ref to if_wd_context_node,lr_context_element type ref to if_wd_context_element.data:lt_selected_elements type wdr_context_element_set.data:ls_some_structure type some_structure.lr_context_node = wd_context->get_child_node( name = 'NAME' ).lt_selected_elements = lr_context_node->get_selected_elements( ).loop at lt_selected_elements into lr_context_element.lr_context_element->get_static_attributes(static_attributes = ls_some_structure).* do something with the element or its attributes.endloop

This code could be used to get all selected elements of a table UIElement and do some processing.back to topHow can I select elements of a node program controlled?You can use the following code to select an element of a context node. In this example the5th element of a context node is selected.data:lr_context_node type ref to if_wd_context_node.data:lv_index type i.lv_index = 5.lr_context_node = wd_context->get_child_node( name = 'NAME' ).lr_context_node->set_selected(flag = abap_trueindex = lv_index).

To select all elements of a context node the following extension of the above example can be used.data:lr_context_node type ref to if_wd_context_node.data:lv_element_count type i.lr_context_node = wd_context->get_child_node( name = 'NAME' ).lv_element_count = lr_context_element->get_element_count( ).do lv_element_count times.lr_context_node->set_selected(flag = abap_trueindex = sy-index).enddo.

To deselect certain elements the parameter 'flag' of the set_selected method has to be set to abap_false.back to topHow can I dynamically create a context node during runtime?You can dynamically create nodes in the context using the utility class cl_wd_dynamic_tool.The following example code creates a new node with the structure SFLIGHT and bind allentries of the SFLIGTH table to this new node.data:lr_rootnodeinfo type if_wd_context_node_info,lr_new_node type if_wd_context_node.data:lt_filgths type table of sflight.lr_rootnodeinfo = wd_context->get_node_info( ).cl_wd_dynamic_tool=>create_nodeinfo_from_struct(parent_info = lr_rootnodeinfonode_name = 'FLIGHTS'structure_name = 'SFLIGHT'is_multiple = abap_true ).lr_new_node = wd_context->get_child_node( 'FLIGHTS ).select * from sflightinto corresponding fields of table lt_flights.lr_new_node->bind_table( lr_flights ).

back to top wd4abap_faq_design1 Comment1. GuestA very good and helpful material. I could clear all my doubts regarding context nodes.