cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic creating a button and adding the event handler to it

former_member187570
Participant
0 Kudos
1,294

Hi Experts,

I am able to create a button dynamically and attached the action

Below is  the code.

data:root type ref to cl_wd_uielement_container,
        bt type ref to cl_wd_button.
 

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

    bt = cl_wd_button=>new_button( text = 'Submit'  on_action = `SAY_HELLO` ).

    cl_wd_flow_data=>new_flow_data( element = bt ).
  
     root->add_child( bt ).

In the method 'SAY_HELLO'  I have written code to show one message. But it gives dump and does not allow me to create onactionsay_hello method even.

I have created SAY_HELLO as method type 1(i.e event handler method).

My expectation is :

One button should be created dynamically and after clicking it should prompt some message . and everything should happen dynamically.

Thanks.


Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
Former Member

I think code written by should work. try once code given by me. Still if you are getting dump. Please share the Dump's snap-shot.

METHOD wddomodifyview .

" For dynamic Programing we need to write code in modify view..
   IF first_time  = abap_true.

     DATA lr_container TYPE REF TO cl_wd_uielement_container.
     DATA: lr_matrix    TYPE REF TO cl_wd_matrix_head_data,
           lr_matrix_lay    TYPE REF TO cl_wd_matrix_layout.


*    ** getting reference  of first ROOTUIELEMENTCONTAINER


     lr_container ?= view->get_element( 'ROOTUIELEMENTCONTAINER' ).
     cl_wd_matrix_layout=>new_matrix_layout( lr_container ) .


* Here we are Creating new button
     DATA: lr_button TYPE REF TO cl_wd_button.
     lr_button = cl_wd_button=>new_
button(
       id = `
button_DYNAMIC`

          text = 'Botton'
       on_action = `METHOD_SHOW`        
     ).

"NOTE: METHOD_SHOW should be statically available in your view... and in that write your code to show data and message

* Here we are adding new button in the TC..
     lr_container->add_child( lr_
button ).

  cl_wd_matrix_head_data=>new_matrix_head_data( lr_
button ).

Former Member
0 Kudos

Hello Chaudhury,

You are trying to map a method to the button, rather you should map an action to the button.

Instead of creating SAY_HELLO as method type 1(i.e event handler method). in method tab

Create an action say_hello in action tab.

I hope it will solve the problem.

Regards,

Rumeshbabu S

Former Member
0 Kudos

Hello Chaudhury,

Refer the following link which explains Creating UI Elements(Table,Buttons) Dynamically in Abap Webdynpro Application.

http://wiki.scn.sap.com/wiki/display/WDABAP/Creating+UI+Elements+Dynamically+in+Abap+Webdynpro+Appli...

Hope this will help you.

Thanks

Katrice