cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Text Edit and Groups

Former Member
0 Kudos

Hi Experts ,

I want to create dynamic text edits and groups.

Thank You.

Accepted Solutions (1)

Accepted Solutions (1)

uday_gubbala2
Active Contributor
0 Kudos

Hi Radhika,

Do go through the links passed on to you by Ashutosh. They are very good blogs written by Thomas Szuecs for working with dynamic programming in webdynpro ABAP. Please use the coding as below to create a group & an textedit element within it.

1) Obtain the reference to the ROOTUIELEMENTCONTAINER

2) Set the desired layout information to it

3) Create the group & textEdit elements with all the default values

4) Provide the layout information to even the group & textEdit elements

5) Add the elements as children to the screen container element

Hope that this is useful for you.

Regards,

Uday

METHOD wddomodifyview .
  DATA: lr_container TYPE REF TO cl_wd_uielement_container,
        lr_group TYPE REF TO cl_wd_group,
        lr_caption_group TYPE REF TO cl_wd_caption,
        lr_textedit type ref to cl_wd_text_edit.
check first_time = ABAP_TRUE.
  lr_container ?= view->get_root_element( ).   "  Get reference of ROOTUIELEMENTCONTAINER

  cl_wd_matrix_layout=>new_matrix_layout( container = lr_container ).

  lr_group = cl_wd_group=>new_group( id = 'GROUP' ).  " Create the GROUP element
  lr_group->set_width( value = '50%' ).

  cl_wd_matrix_layout=>new_matrix_layout( container = lr_group ).
  cl_wd_matrix_head_data=>new_matrix_head_data( element = lr_group ).
  lr_caption_group = cl_wd_caption=>new_caption( text = 'Group Header' ).
  lr_group->set_header( the_header = lr_caption_group ).

" Create the textEdit element
  lr_textedit = cl_wd_text_edit=>new_text_edit( id    = 'TVIEW'  " Provide a unique id to your textedit element
                                                cols  = 20         " Specify the number of columns
                                                rows  = 20        " Specify the number of rows
                                                width = '90%'    " Specify the width
                                                bind_value = 'TEXT' ). " Here we should pass an attribute name to which we want to bind the textedit element to

  cl_wd_matrix_head_data=>new_matrix_head_data( element = lr_textedit ).

" Add the group & textEdit elements as children to the ROOTUIELEMENT container
  lr_container->add_child( the_child = lr_group ).
  lr_group->add_child( the_child = lr_textedit ).
endmethod.

Former Member
0 Kudos

Thanks for the quick response.

I have one more small Qs.

If i want to split a string and display on 2 different lines in the text edit . is it possible ?

for example : Hi all,

this is the layout.

Thank you.

uday_gubbala2
Active Contributor
0 Kudos

Hi Radhika,

Its quite possible to do so.

lr_textedit = cl_wd_text_edit=>new_text_edit( id    = 'TVIEW'
                                                                 cols  = 20         
                                                                rows  = 20        
                                                                width = '90%'    
                                                        bind_value = 'TEXT' ).

As shown above we are trying to bind the value to be displayed in the textEdit with the context attribute named TEXT. So if we can just fill the data in this attribute in the same format then we would get the desired output. You can use the example coding below to get an idea as to how you can populate the attribute that way.

Note: I have declared attribute TEXT of type STRING directly under the root node CONTEXT

METHOD wddoinit .
  DATA: lr_element TYPE REF TO if_wd_context_element,
        s TYPE string.

  lr_element = wd_context->get_element( ).

  CONCATENATE 'Testing'
              'the'
              'idea!' INTO s SEPARATED BY cl_abap_char_utilities=>newline.
  lr_element->set_attribute( EXPORTING name  = 'TEXT'
                                       value = s ).
ENDMETHOD.

Regards,

Uday

Former Member
0 Kudos

Hi Uday ,

Thanks for such helpful replies.

when i try to use your code am getting an error at the follwing line,

lr_container ?= view->get_root_element( ).

It says view is unknown.

Please advice.

Thank YOu

uday_gubbala2
Active Contributor
0 Kudos

Radhika,

You need to code all of this in the WDDOMODIFYVIEW method. This method has the importing parameter VIEW of type if_wd_view. Whenever you want to do any dynamic modifications you need to code only in this method.

Regards,

Uday

Former Member
0 Kudos

Ya figured that out.

One last thing.

I want to do this in a loop.

but i get a dump when i try to give the names of text edit as textv1 , textv2 etc.

Please advice.

Former Member
0 Kudos

Hi ,

I want to create attributes for these text edits at runtime.

Also when i try creating the text edits in a loop, it gives error for the id ..

eg if i useg TEXTE1 , TEXTE2 it g ives a dump.

thank you.

Former Member
0 Kudos

Problem solved.

Thanks Uday.

uday_gubbala2
Active Contributor
0 Kudos

Hi Radhika,

Sorry was busy with some other tasks. Just go through this sample code snippet which does the following.

1) It dynamically creates a context node named CHILD and then creates 4 attributes ATTR1, ATTR2,..

2) Creates a GROUP UI element with a caption attached to it

3) Create 4 textEdit UI elements bound to the 4 context attributes created earlier and embed them within the group

Regards,

Uday

METHOD wddomodifyview.
  DATA: lr_container TYPE REF TO cl_wd_uielement_container,
        lr_group TYPE REF TO cl_wd_group,
        lr_caption_group TYPE REF TO cl_wd_caption,
        lr_textedit TYPE REF TO cl_wd_text_edit,
        lr_node_info TYPE REF TO if_wd_context_node_info,
        lr_node TYPE REF TO if_wd_context_node,
        lr_element TYPE REF TO if_wd_context_element,
        lr_attribute_info TYPE wdr_context_attribute_info,
        content TYPE string,
        attribute_name TYPE string,
	lv_textview_id TYPE string.

  CHECK first_time = abap_true.

  lr_node_info = wd_context->get_node_info( ).

  CALL METHOD lr_node_info->add_new_child_node
    EXPORTING
      name                         = 'CHILD'
      is_mandatory                 = abap_false
      is_multiple                  = abap_true
      is_multiple_selection        = abap_true
      is_singleton                 = abap_false
      is_initialize_lead_selection = abap_true
      is_static                    = abap_false
    RECEIVING
      child_node_info              = lr_node_info.


  lr_container ?= view->get_root_element( ).

  cl_wd_matrix_layout=>new_matrix_layout( container = lr_container ).

  lr_group = cl_wd_group=>new_group( id = 'GROUP' ).
  lr_group->set_width( value = '50%' ).

  cl_wd_matrix_layout=>new_matrix_layout( container = lr_group ).
  cl_wd_matrix_head_data=>new_matrix_head_data( element = lr_group ).
  lr_caption_group = cl_wd_caption=>new_caption( text = 'Group Header' ).
  lr_group->set_header( the_header = lr_caption_group ).


  DO 4 TIMES.
    MOVE sy-index TO attribute_name.

** Preparing the data to be displayed in the textEdit i.e, data for context attribute
    CONCATENATE 'This'
                'is the'
                'data for textEdit number: '
                 attribute_name  INTO content SEPARATED BY cl_abap_char_utilities=>newline.

    CONCATENATE 'ATTR'
                attribute_name INTO attribute_name.

** Condense the ID to ensure that the format is consistent with SAP standard
    CONDENSE attribute_name NO-GAPS.

** Prepare properties of attribute & add to context node CHILD
    lr_attribute_info-name = attribute_name.
    lr_attribute_info-type_name = 'STRING'.
    lr_attribute_info-value_help_mode = '0'.

    lr_node_info->add_attribute( EXPORTING attribute_info = lr_attribute_info ).

    lr_node = wd_context->get_child_node( name = 'CHILD' ).
    lr_element = lr_node->create_element( ).

    lr_element->set_attribute( name  = attribute_name
                               value = content ).

    lr_node->bind_element( new_item             = lr_element
                           set_initial_elements = abap_false ).

** Compute the attribute path dynamically i.e, like CHILD.ATTR1
    CONCATENATE 'CHILD.'
                attribute_name INTO attribute_name.
    CONDENSE attribute_name NO-GAPS.
    lr_textedit = cl_wd_text_edit=>new_text_edit( cols  = 10
                                                  rows  = 5
                                                  width = '90%'
                                                  bind_value = attribute_name ).

    cl_wd_matrix_head_data=>new_matrix_head_data( element = lr_textedit ).

    lr_group->add_child( the_child = lr_textedit ).
  ENDDO.
  		
lr_container->add_child( the_child = lr_group ).
ENDMETHOD.

Answers (1)

Answers (1)

former_member185029
Active Contributor
0 Kudos

This might help you

-Ashutosh