cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the 'text' property value of a button in coding?

Former Member
0 Kudos

Hi Experts,

I'm using 10 buttons all are having common action('click'). when i click a button the 'text' value of the button should pass to a function.So the action is same but the passed value will be the 'text' value of the corresponding button. I don't know how to get the 'text' property of a button in coding. Kindly help me to solve this problem.

Thanks and Regards

Basheer

Accepted Solutions (1)

Accepted Solutions (1)

siddharth_jain
Active Contributor
0 Kudos

Hi,

For getting the text value property of a button after the Button click you can write the following code in wdDoModify view of view:

IWDButton button = (IWDButton)view.getElement("<Button id>");

button.getText();

But i am not sure how you distinguish between which button is clicked ,Because you are using same event handler for all of them.

Siddharth

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

bind the button text property with context attribute of string.

InDoinit of view set the required name.

when ever you require you can get it like this,

wdContext.currentContextElement().getButtonName();

Regards,

ramesh

Former Member
0 Kudos

That would require 10 additional context attributes.

Armin

Former Member
0 Kudos

Hi Armin,

just to avoid DoModify i said like that !

Regards,

ramesh

Former Member
0 Kudos

Hi,

My event is like this.

public void onActionclick(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

String s = ? ; // should get the 'text' property of clicked button

fillInput(s); // function to be called

}

The called function is,

public void fillInput( java.lang.String id )

{

String str=wdContext.currentContextElement().getNum();

str = str + id;

wdContext.currentContextElement().setNum(str);

}

How can i get the 'text' property value of the corresponding button. Click action should be common to all buttons.

Thanks and Regards,

Basheer

Former Member
0 Kudos

Just read my answer above.

Armin

Former Member
0 Kudos

I did not say that your proposal is wrong, but creating 10 additional attributes is a little bit tedious in that case. Using method wdDoModifyView() for what it is designed is perfectly ok.

Armin

Former Member
0 Kudos

I am not sure why you need the (localized) button text in the action handler but you can achieve this using event parameter mapping:


wdDoModifyView(...)
{
  if (firstTime)
  {
    /* assuming the buttons are named "Button1", "Button10" */
    for (int i = 1; i <=10; ++i)
    {
      IWDButton button = (IWDButton) view.getElement("Button" + i);
      button.mappingOfOnAction().addParameter("text", button.getText());
    }
  }
}

Now if you add a parameter "text" of type string to the common action handler, it will contain the text of the pressed button.

Armin