cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the Id of the Button which is clicked?

Former Member
0 Kudos

Hi,

I am having some 10 buttons and in the on action property these button i'm opening a popup.

I have mapped all the 10 buttons to same action. so i want to know in onAction which button is clicked.

so how to get the Id of the button clicked in the on action?

Help me out with the detailed code.

Thanks,

Suresh

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

Write this code in the "wdDoModifyView()" method:


//let's say the first button ID is btn1

IWDButton buttonOne = (IWDButton) view.getElement("btn1");

buttonOne.mappingOfOnAction().addParameter("commandID","btn1");

//let's say the second button ID is btn2

IWDButton buttonTwo = (IWDButton) view.getElement("btn2");

buttonTwo.mappingOfOnAction().addParameter("commandID","btn2");

Add the parameter "commandID" to the event handler of ur buttons and it should be of type "String". That will look like:


public void onActionTest(IWDCustomEvent wdEvent, String commandID){

//here commandID contains the ID of the button which was clicked

 wdComponentAPI.getMessageManager().reportSuccess(commandID);
}

regards

Surender Dahiya

Former Member
0 Kudos

A small correction - Put wdDoModifyView() code in

if(firstTime) { ...}

piyush_kumar6
Active Contributor
0 Kudos

hi Suresh,

in your case no need to get id of buttons , you can open a window using

id but it will be a long process.

you just create a value attribute of type string

*let you have created value attribute named "myButton" *

now on every button click you set the value in myButton. like

wdContext.currentContextElement().setMyButton("your value");

now check value of button and write your desired code .

Former Member
0 Kudos

Hi,

Create a parameter to the action lets say id of type string

Do a source mapping as follows


IWDButton b1 = (IWDButton)view.createElement(IWDButton.class);
	  //In older verion use addParameter
	  b1.mappingOfOnAction().addParameter("id","Button1");
	  b1.mappingOfOnAction().setString("id","Button1");

//Do the same for rest of the buttons

Regards

Ayyapparaj

Former Member
0 Kudos

This code is not correct: You create a button with an automatically assigned ID, but you pass "Button1" to the action handler. The correct code would be


IWDButton b1 = (IWDButton) view.createElement(IWDButton.class, "Button1");
b1.mappingOfOnAction().addParameter("id", b1.getId() );

Armin

Former Member
0 Kudos

Hi Ayyapparaj,

i have alreday created buttons, i'm not creating it dynamically. In that case how to know which button was clicked. Say that i'm having 5 buttons btn1, btn2, btn3, btn4, btn5. And i have mapped all this buttons to same action "btn_click" with a parameter "id".

then how to know which button is clicked? help me out with detailed procedure..

Thanks ,

Suresh

Former Member
0 Kudos

wdDoModifyView(...)
{
  if (firstTime)
  {
    for (int i = 1; i <=5; ++i)
    {
      IWDButton button = (IWDButton) view.getElement("btn" + i);
      button.mappingOfOnAction().addParameter("id", button.getId());
    } 
  }
}

Or better: If you have an IDE that contains the parameter mapping editor, use it and don't write code.

Armin

Former Member
0 Kudos

Hi Suresh,

Can you tell me how you acheived that ?

I am not able get the id of the uielement inside action

Best Wishes

Idhaya R

Former Member
0 Kudos

Hi ,

See the link.... It will help u..

https://forums.sdn.sap.com/click.jspa?searchID=12926782&messageID=5401932

Regards,

Sunitha Hari