cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Binding of an action with a button . (Its urgent Please reply)

Former Member
0 Kudos

Hi all

I have a problem. I want to bind an action to a button based on the text for that button. I'm changing the text of the button based on the selection criteria.

I've created separe actions. I want to bind the action with button based on the text. Is it possible. If so anybody please help me.

Thanks and Regards

Aparnna

Accepted Solutions (1)

Accepted Solutions (1)

monalisa_biswal
Contributor
0 Kudos

create a parameter for the action say "text".Now map button's text property to this text parameter of the event.

in the wdDomodifyView() write the following code.

IWDButton btn=(IWDButton)view.getElement("Button1");
		btn.mappingOfOnAction().addParameter("text",btn.getText());
		IWDButton btn2=(IWDButton)view.getElement("Button2");
			btn2.mappingOfOnAction().addParameter("text",btn2.getText());

In the onAction method get the value of text parameter and accordingly handle ur code.

Hope it helps.

Former Member
0 Kudos

Hi all

Thank you all for your valuable help.

Hi Monalisa

I used ur code. Now I'm using only one action. Based on the button text i'm triggering the event.

Regards

Aparnna

Answers (5)

Answers (5)

Former Member
0 Kudos

Sorry in my previous msg, instead of getAction I coded getElement please ignore it. It should be as below

........... IWDButton button = (IWDButton) view.getElement(IWDButton.class, "buttonid");

........... IWDAction action1 = (IWDAction)view.getAction("action1id");

........... IWDAction action2 = (IWDAction)view.getAction("action2id");

........... If(button.getText().equalsIgnoreCase("App"){

..................button.setOnAction(action1);

..................button.setText("App2");//toggling button text

............}

...........else{

..................button.setOnAction(action2);

..................button.setText("App");//toggling button text

...........}

former_member185029
Active Contributor
0 Kudos

hi

Not sure what went wrong with ur code...

try

IWDButton button = (IWDButton) view.getElement( "buttonid");

This is working for me.

Also if possible, give me your email so that i can send you the project.

Mine email:ashu_moharir@yahoo.com

Regards,

Ashutosh

Former Member
0 Kudos

Hi Ashutosh

First I was using ToolBarButton in the table. Then it was not working. After that i tried using the normal IWDButton. Then also it didn't work.

When i click on that button the window stays there as such. I've done exactly as u have specified. Did u read my problem? I'm using a dialog window.

Please go through the tutorial links that Anil has given. I've followed that tutorial to create a dialog window.

I've sent a mail to ur mail id.

Regards

Aparnna

Former Member
0 Kudos

Hi Aparna,

You can try this:

1. Create two actions at design time, say action1 and action2

2. In wdModifyView toggle the text of ur Button, and bind action dynamically as follows:

........... IWDButton button = (IWDButton) view.getElement(IWDButton.class, "buttonid");

........... IWDAction action1 = (IWDAction)view.getElement(IWDAction.class, "action1id");

........... IWDAction action2 = (IWDAction)view.getElement(IWDAction.class, "action2id");

........... If(button.getText().equalsIgnoreCase("App"){

..................button.setOnAction(action1);

..................button.setText("App2");//toggling button text

............}

...........else{

..................button.setOnAction(action2);

..................button.setText("App");//toggling button text

...........}

I think this will work

Regards,

Aparna .P

Former Member
0 Kudos

hi

good

go through this link, i hope this ll help you to solve your problem

/people/thomas.szcs/blog/2006/01/03/dynamic-programming-in-web-dynpro-abap--part-ii-handling-viewelements

thanks

mrutyun^

Former Member
0 Kudos

Hi Aparnna,

Do the foolowing

1.Bind text property of Button to a valueattribute.

2.create an action and bind it tothe button ( Nonned to create many actions )

3.In the action handler,access the vaueattributeand based on the value you can write the logic

Ex :If(wdContext.currentContextElement().getButtonText().equals("Create")

//Do 1

else

If(wdContext.currentContextElement().getButtonText().equals("Save")

Regards,Anilkumar

Former Member
0 Kudos

Hi Anil

My I'm using a dialog window, that pops up when a user clicks a button.

Suppose there are 4 buttons in the main vew.

Application, Module, Version etc.

When a person clicks Application a window comes with all the selectable attributes displayed as a table.

I want the selected values back in the first view.

For each button i want this to happen. Creating a window for each is not a good thing to do(that's my view). So I'm trying to integrate everything in a single window, inside that a single view.

I want separate events to be fired , depending on the button text.

Based on the selection made by the user i want to fetch data from database.

Regards Aparnna

Former Member
0 Kudos

Hi,

Still i feel you can do this by simple context binding instead of complicating the things!!!

You have MainView with 4 buttons...you have 1 view having table.

you can create valueAttribute "ButtonText" on both the views and do context mapping.

in the Tableview(secondview) , you can read the buttontext through context and display the attributes accordingly.

Regards,Anilkumar

former_member185029
Active Contributor
0 Kudos

Aparna,




IWDButton button =(IWDButton) view.getElement("buttonId");
IWDAction action = null;
if(condition1)
{
 action = view.getAction("action1");
}
else if(condition2)

{
 action = view.getAction("action2");

}

button.setOnAction(action);


Former Member
0 Kudos

Hi Anil

This i've done already.

First i've done this for a single button. Not using this context variable for button text. When i click on that button this window will close and control is transfered to the first view. For a single button everything is working fine.

If you want i'll send the tutuorial i've followed for creating the dialig window.

Regards

Aparnna

Former Member
0 Kudos

Hi Ashutosh

I tried ur code. Bt the button gets disable when i click on that.

And the action is not firing

Regards Aparnna

former_member185029
Active Contributor
0 Kudos

Aparna

You can create an object of push button in wdDoModify method

and there on checking certain conditions you can apply actions.

Ashutosh

Former Member
0 Kudos

Hi Ashutosh

Would you please explain that?

Aparnna