aspose file tools*
The moose likes Struts and the fly likes How to call a method from an action class using Struts 2. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to call a method from an action class using Struts 2." Watch "How to call a method from an action class using Struts 2." New topic
Author

How to call a method from an action class using Struts 2.

Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Hi All,
I have a situation where I have to call an action class , when there is a change in the values of a dropdown box that im implementing using struts 2 tags , im trying to use javascript for this and need to pass a variable to the function being called > Could anyone please help me with an example .Thanks.


Learning and Learning!-- Java all the way!
Raza Mohd
Ranch Hand

Joined: Jan 20, 2010
Posts: 247

There are various option you can use for Ajax Calling .
like dwr ,Json ,jQuery..

but there is one more option to call action without using it.

Call a Javascript method on change event of dropdown and submit your form there.


Best Regards
Mohd Raza

Good luck!!
A small leak can sink a Gigantic ship.>
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

I intend to use Javascript , could you please provide an example. Thanks
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Bounce! Any help would be appreciated.
Nick Sher
Ranch Hand

Joined: Nov 10, 2008
Posts: 78
Vic Hood wrote:Hi All,
I have a situation where I have to call an action class , when there is a change in the values of a dropdown box that im implementing using struts 2 tags , im trying to use javascript for this and need to pass a variable to the function being called > Could anyone please help me with an example .Thanks.


Try this,
In your javascript method you will have


Nick
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Im sorry, but i couldnt understand your example.Could you please explain it further?
Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 270

post your code Vic .. it will help us help u....


Time is what we want the most, but what we use the worst. -- William Penn
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Robin John wrote:post your code Vic .. it will help us help u....

Thanks for replying Robin. Well Im hoping to load a list on the basis of a parameter passed through the dropdown. The code for the dropdown and the javascript that i have currently written but does not work is as follows



How do i go about writing the Javascript function to acheive what I need? Thanks
Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 270

Hey Vic, sorry for the late reply, was stuck on something else..... look at the below code.. it should work... (I have not tested it.. please test it)



you can use "actionName!methodName.action" in the URL to go to "methodName" method.
poornimaa ananth
Greenhorn

Joined: Mar 23, 2012
Posts: 3
Hi,

I Am working on struts 2 to be deployed on IBM portal server. Need to use ajax. when a textfield is populated an action has to be invoked. based on the result a dropdown has to be enabled or disabled. I have tried the other samples provided in the thread but with no result. Need help asap. Thanks in advance.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to call a method from an action class using Struts 2.