how to populate values in dropdownbykey in webdynpro

来源:互联网 发布:mysql可以没有主键吗 编辑:程序博客网 时间:2024/06/05 07:49

There are 2 types of dropdown ui elemts:

1. For DropDownByIndex UI element we need to bind the text property to an attribute within a context node, which contains several elements (cardinality = 0..n). The number of elements defines the possible entries in the list. In the WDDOINIT method we can prepare an internal table with the values and bind it to the node and the lead selection defines the selected element.

For example if u have defined a node 'TEXT' with cardinality '0..n' with attribute TEXT. Bind the text property of DropDownbyIndex UI element to attribute Text of context node Text.

In the WDDOINIT method you can prepare an internal table with the values and bind it to the node and the lead selection defines the selected element.

The below code sample may help.

  1. method WDDOINIT .
  2. data:
  3. node_text type ref to if_wd_context_node,
  4. stru_text type if_componentcontroller=>element_text,
  5. tab_text type if_componentcontroller=>elements_text .
  6.  
  7. node_text = wd_context->get_child_node( name = if_componentcontroller=>wdctx_text ).
  8.  
  9. * Set/fill your values
  10. stru_text-text = 'Value1'.
  11. append stru_text to tab_text.
  12.  
  13. stru_text-text = 'Value2'.
  14. append stru_text to tab_text.
  15.  
  16.  
  17. * set values to the node
  18. call method node_ddi_also_text->bind_table
  19. exporting
  20. new_items = tab_text.
  21.  
  22.  
  23. endmethod.

2. For DropDownByKey UI element bind the SelectedKey property to an attribute within a context node. Then you must provide the fixed values (table with key value combination) in a different way and store them in the node info. We can use the elements get_attribute method to get the attribute value which user has selected.

For this we need to use the interface IF_WD_CONTEXT_NODE which has a method GET_NODE_INFO, which returns meta information on the respective node. This information is of type IF_WD_CONTEXT_NODE_INFO.

Kindly refer the following code:

  1. method WDDOINIT .
  2.  
  3. data: NODE_INFO type ref to IF_WD_CONTEXT_NODE_INFO,
  4. NODE type ref to IF_WD_CONTEXT_NODE.
  5. NODE = WD_CONTEXT->GET_CHILD_NODE( 'NODE1' ).
  6. NODE_INFO = NODE->GET_NODE_INFO( ).
  7.  
  8.  
  9. * To be able to store the fixed values for the attribute in the node info, two
  10. *additional variables are necessary:
  11.  
  12. data: LT_VALUESET type WDR_CONTEXT_ATTR_VALUE_LIST ,
  13. L_VALUE type WDR_CONTEXT_ATTR_VALUE.
  14.  
  15. *WDR_CONTEXT_ATTR_VALUE is a data type defined in the DDIC. It contains *two components KEY and VALUE, both of type STRING.
  16.  
  17. *WDR_CONTEXT_ATTR_VALUE_LIST is a table type stored in the DDIC, whose *rows are of type WDR_CONTEXT_ATTR_VALUE.
  18.  
  19. *The two variables created in the source text example are used to accept the value *pairs that will later be passed to the node info.
  20.  
  21. L_VALUE-VALUE = 'V1'.
  22. L_VALUE-TEXT = 'yesterday'.
  23. INSERT L_VALUE into table LT_VALUESET.
  24.  
  25. L_VALUE-VALUE = 'V2'.
  26. L_VALUE-TEXT = 'today'.
  27. INSERT L_VALUE into table LT_VALUESET.
  28.  
  29. L_VALUE-VALUE = 'V3'.
  30. L_VALUE-TEXT = 'tomorrow'.
  31. INSERT L_VALUE into table LT_VALUESET.
  32.  
  33.  
  34. NODE_INFO->SET_ATTRIBUTE_VALUE_SET (
  35. NAME = 'ATTRIBUTE1'
  36. VALUE_SET = LT_VALUESET ).
  37.  
  38. endmethod.


阅读全文
0 0
原创粉丝点击