File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Trigger action on combo change Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Trigger action on combo change" Watch "Trigger action on combo change" New topic
Author

Trigger action on combo change

kiran chirravuru
Greenhorn

Joined: Nov 25, 2009
Posts: 26
Hello please help me how to trigger action method in action class on combo change
event in struts 2.0


Regards
Kiran
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Do you want to make an AJAX request or post back the page when the combo box's value is changed?? Both can be achieved easily with the onchange event of the s:select tag. Try to find a simple tutorial on google...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
kiran chirravuru
Greenhorn

Joined: Nov 25, 2009
Posts: 26
I want to perform some operations in the method and post back again to the same page.
How can we do that without using ajax or with using ajax
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

That's easy to do, in the onchange event of your combo box, you can write this javascript

This will submit the form to the server (of course for this to work, the action attribute of your form must point to the current action)...
kiran chirravuru
Greenhorn

Joined: Nov 25, 2009
Posts: 26
Ankit thanks for your response

But actually i need to trigger different action method in the Action class on combo click and trigger different action
method in the Action class when the form is submit


Regards
Kiran
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

I'm still not sure whether you want to post back your page or not. If you want to use AJAX to do this, its a completely different thing, if you want to post back the page, its a completely different thing. Basically what exactly do you want to do?? I'll give you two scenarios

1. I have a site which is customized as per regions (like Nokia's site). I have a combo box of region on my site. On the basis of the region selected by the user, I want to send the user to a specific page. I'll post back the page in this case.

2. I have a site which sells products. I have a combo box for countries for the shipping address. On the basis of the country selected by the user, I want to show the total shipping cost of the product. Since in this case all that I want is just a simple calculation, I would use AJAX and not post back the page.

So what exactly do you want?? Your question is too ambiguous if you ask me. Its very tough to help if the goal is not clear...
kiran chirravuru
Greenhorn

Joined: Nov 25, 2009
Posts: 26
I want actually the first scenario how can i achieve this
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

That's very simple to do. Suppose on the change of the combo box, you want to submit to a URL like change.action and send the combo box value as a request parameter like comboVal, then you can do this on the onclick event of the combo box
kiran chirravuru
Greenhorn

Joined: Nov 25, 2009
Posts: 26
hello ankit can you give me your mobile number
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

kiran chirravuru wrote:hello ankit can you give me your mobile number

And why would you want that for?? If you have any questions, you can ask it here
kiran chirravuru
Greenhorn

Joined: Nov 25, 2009
Posts: 26
Hello ankit
Here is the detailed scenario of my problem

I using struts 2.0 for my web application development . I have two methods in my action class .

From my jsp i want to trigger particular action method in the action class on combo change and different action method in the same
action class when my form is submitted and then i again i want to come back again to same jsp page.

But in the struts-config.xml in the action mapping we can define only one action class and one action method
at a time . So how can i achieve this scenario.

Regards
kiran


 
 
subject: Trigger action on combo change
 
Similar Threads
Struts 2.0
JPanel and JFrame listener
How to submit a page on change of Combo using Struts
JComboBox problem
one key press