cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamically Creating UI Elements and Binding to Context ?

Former Member
0 Kudos

Im having a bit of trouble...

I have a context node that consists of attributes name and value with cardinality 0..n.

NODE

- name

- value

I now want to be able to loop at the node and create a new UI element for each entry, for example a TextField with a Label,

The TextField's value will need to be bound to the value attribute, and the Label's value bound to the name attribute.

This will give something like this on the UI:

Element1: name: [ value ]

Element2: name: [ value ]

Element3: name: [ value ]

Now the part that I am struggling with is how to bind these elements.


lr_input = cl_wd_input_field=>new_input_field(
  bind_value = 'NODE.VALUE'    <---------- This bit im struggling to bind correctly.
  id         = 'INPUT_ID_XXX' ).

So basically I need to bind each element to an entry on the context, however Im struggling to find out how to do this.

Any help would be great.

Many Thanks.

Edited by: Jonathan Dawber on Aug 7, 2009 3:08 PM

Accepted Solutions (0)

Answers (3)

Answers (3)

uday_gubbala2
Active Contributor
0 Kudos

Now I go to my layout and place a MultiPane UI element on it. I then embed a TransparentContainer within this MultiPane UI element. I then embed 1 Label & TextView element within my TransparentContainer.

I then bind the:

"Text" property of my Label to the "Name" attribute. (i.e, MAIN.NODE.NAME)

"Text" property of my TextView to the "Value" attribute (i.e, MAIN.NODE.VALUE)

"dataSource" property of my MultiPane to my context node "NODE" (i.e, MAIN.NODE)

That't all! You would have achieved your desired functionality of creating that many number of Label & TextView elements dynamically & binding them to the appropriate element. You can try these resources for additional information about working with the MultiPane UI element;

[Link 1|http://help.sap.com/saphelp_erp2005/helpdata/en/df/da8b412bb5b35fe10000000a1550b0/content.htm]

[Link 2|https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/106209dd-edc9-2b10-b4a5-911ef18aac89]

Regards,

Uday

uday_gubbala2
Active Contributor
0 Kudos

Hi Jonathan,

You can completely avoid all this confusion by directly making use of the MultiPane UI element instead. You are better off avoiding dynamic programming as much as you can and try to design the same statically using the MultiPane element. This element would take care of the bindings correctly. I will explain as to how you can achieve the same intended functionality using the MultiPane UI element.

I am having a context node by name NODE with 2 string attributes NAME & VALUE. Am populating some data to my node within the WDDOINIT method as shown below:

METHOD wddoinit .
  DATA: lr_node TYPE REF TO if_wd_context_node,
        lt_data TYPE wd_this->elements_node,
        wa_data TYPE wd_this->element_node,
        lv_str TYPE string.

  DO 4 TIMES.
    lv_str = sy-index.
    CONCATENATE 'Name:'
                lv_str INTO wa_data-name.
    CONCATENATE 'Value:'
                lv_str INTO wa_data-value.
    APPEND wa_data TO lt_data.
    CLEAR wa_data.
  ENDDO.

  lr_node = wd_context->get_child_node( name = wd_this->wdctx_node ).
  lr_node->bind_table( lt_data ).
ENDMETHOD.

Former Member
0 Kudos

Hi,

Do you want to create the Input fields for those or text fields.

If your node has 0:N entries, then get the table entires.

Loop through this table and then inside this for each record pair you need to create labels and input fields and bind those

properties to that record values.

Check out this link -

Regards,

Lekha.