This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Raza Mohd
Ranch Hand
Posts: 247
Java MyEclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I intend to use Javascript , could you please provide an example. Thanks
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bounce! Any help would be appreciated.
 
Nick Sher
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im sorry, but i couldnt understand your example.Could you please explain it further?
 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
post your code Vic .. it will help us help u....
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic