cancel
Showing results for 
Search instead for 
Did you mean: 

How insert a Group into RootUIElement dynamically?

Former Member
0 Kudos

Hi,

how is it possible to add a dynamically created UI Element (Group) to ROOTUIELEMENTCONTAINER? I try it with the following piece of code but i get always the error message: <b> Access via 'NULL' object reference not possible. </b>


  IF FIRST_TIME EQ ABAP_TRUE.

    DATA: lr_root TYPE REF TO cl_wd_uielement_container,
          lr_groupbox TYPE REF TO cl_wd_group.
                                
    lr_root ?= view->get_element( 'ROOTUIELEMENTCONTAINER' ).

    lr_groupbox ?= cl_wd_group=>new_group( id = 'GROUP' ).

    cl_wd_flow_data=>new_flow_data( lr_groupbox ).

    lr_root->add_child( lr_groupbox ).

  ENDIF.

What is my mistake?

regards,

Sharam

Message was edited by:

Sharam Pourmir

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Sharam,

Firstly, I am not getting a null pointer exception. I got an ASSERT condition violated error, which I solved by defining a layout for the group. The layout has to be defined first and then the layout data. This is my code and it works. Try if it does for you too.

IF FIRST_TIME EQ ABAP_TRUE.

DATA: lr_root TYPE REF TO cl_wd_uielement_container,

lr_flow_layout type ref to cl_wd_flow_layout,

lr_groupbox TYPE REF TO cl_wd_group.

lr_root ?= view->get_element( 'ROOTUIELEMENTCONTAINER' ).

lr_groupbox ?= cl_wd_group=>new_group( id = 'GROUP' ).

CALL METHOD CL_WD_FLOW_LAYOUT=>NEW_FLOW_LAYOUT

EXPORTING

CONTAINER = lr_groupbox

RECEIVING

CONTROL = lr_flow_layout

.

lr_groupbox->set_layout( lr_flow_layout ).

cl_wd_flow_data=>new_flow_data( lr_groupbox ).

lr_root->add_child( lr_groupbox ).

ENDIF.

Regards,

Nithya

Former Member
0 Kudos

Hi Nithya,

thank you for your reply. Now i know my mistake. I didn't have use cl_wd_flow_layout.

regards,

Sharam

Former Member
0 Kudos

Hi all

Can you say, how i can add element to group dinamycally?

<b>UPD: lr_group->add_child( LR_LABEL ).</b>

Sorry

Message was edited by:

Andrey Semenchenko

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Sharam,

Just a question here. Is this the exact code that you are using or is there something different that you have coded? In my case, the problem was that I was using matrix layout and I had to use the following

lr_matrix_layout = cl_wd_matrix_layout=>new_matrix_layout( lr_groupbox ).

lr_matrix_head_data = cl_wd_matrix_head_data=>new_matrix_head_data( lr_groupbox ).

Previously I was just using new_matrix_head_data and it was not working because of that.

Regards,

Neha

Former Member
0 Kudos

Hi,

Instead of the method get_element, try using get_root_element. Your rootuielement container is a transparent container. So the following code might help:

data: lr_container type ref to cl_wd_transparent_container.

lr_container ?= view->get_root_element( ).

Then create a group and do an add_child. It should work.

Regards

Nithya

Former Member
0 Kudos

Hi Nithya,

It does not work with get_root_element either. The two methods, get_root_element and get_element ('ROOTUIELEMENTCONTAINER') basically do the same thing. The problem is somewhere with the group box insertion.

Regards,

Neha

Former Member
0 Kudos

Hello!

I tried creating a Group myself. But I was getting the same error. I am not sure why this is happening. I will check again and get back. Do let me know if you find the answer.

Regards,

Neha