cancel
Showing results for 
Search instead for 
Did you mean: 

Creating Dynamic action handler for dynamic buttons

Former Member
0 Kudos

Hi Experts,

My requirement is based on the select query , I am getting 'n' number of records in my internal table and now I need to create that 'n' number of Buttons dynamically in my Webdynpro Layout and also create same number of dynamic Action Handlers to assign the same to those dynamically created buttons.

So please let me know can we create dynamic action handlers in the code itself rather than creating manually in the view controller or component controller.

Regards,

Vishal Chauhan

Accepted Solutions (1)

Accepted Solutions (1)

RicardoRomero_1
Active Contributor
0 Kudos

Hi Vishal,


I think is not possible to create the action handler dinamically.
You can create one generic method for all your buttons and modify the logic in the code depending on the name of the button you can get from the parameter WDEVENT.

Regards,

Former Member
0 Kudos

Dear Ricardo,

Thanks a lot for your reply.

Actually on runtime , I am creating the buttons dynamically , so it may be 'n' number of buttons . So in that case , I am not sure , how can I get the the button details in WDEVENT. Based on the button click , I need to findout which button is clicked and perform the action.

Regards,

Vishal chauhan

RicardoRomero_1
Active Contributor
0 Kudos

Hi Vishal,


You have to assign a name to each button. When a button is pushed you have the name inside the parameter WDEVENT, there is a table with some values, you can read the ID.


Anyway, for your requirement may be is not necessary to create the buttons dynamically, I think you can use a Row repeater UI Element or as Amy said a table and read the CONTEXT_ELEMENT.

Former Member
0 Kudos

Hi Ricardo,

I have tried to read the pushed Button ID through WDEVENT. There is a hashed table called PARAMETERS having Name and Value fields.

But now when I am trying to read the value of the Button ID , I am not able to compare it with any variable or convert the same into variable .

So kindly help me in the same.

My requirement is to get the pushed Button ID and than compare it with my other variable.

Regards,

vishal 

former_member199125
Active Contributor
0 Kudos

Hi Vishal,

You need to create one action , while creating button dynamically assing that action.

In action declare a parameter ID type string. whenever the action trigger ID will contain BUTTON ID.

So declare your button id according to your requirement.

Regards

Srinivas

Former Member
0 Kudos

Hi Srinivas,

Thanks for your reply.

But how will that Parameter ID contains the button ID automatically . What I needs to done for getting the button ID in the string Parameter ID .

Can you please expain me in details as I am stuck here .

Regards,

Vishal Chauhan

Former Member
0 Kudos

Hi Srinivas,

Thanks for your reply. It works .

Can you please let me know , same way can we findout the Text of the button through any parameter.

Regards,

Vishal Chauhan

Answers (2)

Answers (2)

faebulicious
Explorer
0 Kudos

Create just one action for all your buttons. At runtime when you're creating the buttons, you can add any additionaldata (despite from an ID) using the method MAP_ON_ACTION.

data:

    lt_params type wdr_name_value_list

  , ls_param type wdr_name_value

  .

ls_param-name = 'ANY_NAME'.

ls_param-value = 'YOUR_VALUE'.

append ls_param to lt_params.

lo_button->map_on_action( lt_params ).

In your action, you can access these parameters again.

lv_your_value = wdevent->get_string( 'ANY_NAME' ).

amy_king
Active Contributor
0 Kudos

Hi Vishal,

I don't think you need to create the buttons or actions dynamically. If I understand your requirement, you want to display one button for each row of your internal table.

In your view layout, create a TableColumn that contains a button and assign the button an onAction event. When you create the action for the button, select the option "Transfer UI Event Parameters" from the wizard dialog. Selecting this option gives you two additional importing parameters in your method signature, one of which is CONTEXT_ELEMENT. The parameter CONTEXT_ELEMENT tells you in which row of the internal table the button was clicked.

If you have already created the action and its handler method, you can manually add the CONTEXT_ELEMENT importing parameter to the method signature. Use type ref to IF_WD_CONTEXT_ELEMENT.

You can also programmatically read the context element from WDEVENT with the statement,

wdevent->get_context_element( name = 'CONTEXT_ELEMENT' )

Cheers,

Amy

Former Member
0 Kudos

Hi Amy,

I have created buttons dynamically , but now I want to get the ID of the button which user pressed in my variable toperform further process. I am getting the Button ID through WDEVENT Parametre but in the form of Hashed Internal table of Ref type CL_WD_CUSTOM_EVENT , So I am not able to get that ID in my string variable.

So can you please help me out on this.

Regards,

Vishal Chauhan