cancel
Showing results for 
Search instead for 
Did you mean: 

how to get the button ID in WebDynpro

Former Member
0 Kudos

Hi,

In my WebDynpro application I have a Button, and on click of the button, I have a capture the button ID. Please suggest me how to do that.

Regards,

Umapathi

Accepted Solutions (1)

Accepted Solutions (1)

former_member185086
Active Contributor
0 Kudos

Hi

Simply you can achieve this by [parameter mapping|http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/0038f00f-9dfe-2b10-69a4-f1ce24d55d59&overridelayout=true]

BR

Satish Kumar

Former Member
0 Kudos

Hi All,

I want to Capture the ID of Button on which I click.

Here is a senario...

I have Button (with the button UI id is "button_id") and an action GO and an evnt handler

onActionGO(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent) {

// here i am going to call one method which takes the string argument and i have to pass the button id

callMethod(button_id)

}

so tell me now...how to get the button id on click of my button GO.

Former Member
0 Kudos

Why do you need the button ID at all?

Armin

gill367
Active Contributor
0 Kudos

Use kaushal's method if you are having more than one buttons using the same eventhandler.

Otherwise go to layout and click on button and in properties check its id.

that you can directly pass.Hardcode this as the parameter.

Regards,

sarbjeet

Former Member
0 Kudos

Hi,

I have two buttons in my application (for example button_id1 and button_id2) which call the same event handler (as metined above onActionGO)

And in the callMethod() i am passing the button id as a argument...

if(button_id1) then display the popup window on top of the page...else

if (button_id2) then display the popup window on bottom of the page...

onActionGO(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent) {

callMethod(button_id);

}

callMethod(String buttonID) {

// I have a logic to open the popup that is to open the window

if(buttonID == "button_id1")

window.setWindowPostions(WDWindowPos.TOP);

} else {

window.setWindowPostions(WDWindowPos.BOTTOM);

}

Former Member
0 Kudos

And why don't you use separate actions / handlers?

Armin

Former Member
0 Kudos

Hi Armin,

I can have separate handler, but the problem is in the method callMethod() I have more code written and in which method I will be opening the popup window which is based on button_id. So for me to FIND OUT THE BUTTON ID IS ESSENTIAL.

Former Member
0 Kudos

That's not true. There are very good reasons not to use UI element IDs inside the controller code. Why not just creating two different actions and calling your common method with different parameter values from the different action handlers?

Armin

Answers (3)

Answers (3)

former_member40425
Contributor
0 Kudos

In the onActionGo write following code.

String button_Id = wdEvent.getString("buttonId");

I hope it helps.

Regards,

Rohit

Former Member
0 Kudos

I assume you have associated one Action to more than one buttons, and in the action event handler you want to determine the Button which has triggered the event.

This can be achieved through parameter mapping. In wdDoModify method add the following piece of code.

if(firstTime) {
    	IWDButton button1 = (IWDButton)view.getElement("<button1_id>");
    	IWDButton button2 = (IWDButton)view.getElement("<button2_id>");
    	
    	button1.mappingOfOnAction().addParameter("button_id","<button1_id>");
    	button2.mappingOfOnAction().addParameter("button_id","<button2_id>");
    }

In the action event handler, you can determine the id of the button as under.

String buttonId = wdEvent.getString("button_id");

Regards

kk..

srinivas_sistu
Active Contributor
0 Kudos

Hi,

Can you please explain what is your requirement???

If you want to capture the button Id value on action of some other UI Element, what you can do is

Create a context attribute of type String and assign this variable to the ID property of the required Button.

Now in DoInIt() method, set this button ID context variable. Now you can access this button where ever you want by using

wdcontext.yourContextElement().getVa_ButtonID()... where Va_ButtonID is the context attribute you created and mapped to the ID Property of the button.

Regards,

SrinivaS