Reputation: 856
In Controller, i am getting a list from the Database and then setting it in the command object which will be used further on JSP. To show the dropdown, i am using this list. Now i want to invoke methods on the basis of the dropdown values selected from JSP for e.g. if i selected value 'A' from dropdown, then it should call method A() of the controller, if 'B' then method B() and so on. Can someone guide me from where to start.
Upvotes: 0
Views: 1295
Reputation: 2587
You can have your Request mapping like:
@Controller
@RequestMapping("/test")
public class testController{
@RequestMapping("/first")
methodFirst(){
//your code
}
@RequestMapping("/second")
methodSecond(){
//your code
}
@RequestMapping("/third")
methodThird(){
//your code
}
}
You jsp page would be something like:
<select id="testSelect">
<option value="first">1</option>
<option value="second">2</option>
<option value="third">3</option>
</select>
Use jquery to change window.location on change of option in list:
${"#testSelect"}.onChange(){
window.location="${context}/test/"+this.value();
}
What are we doing here is, we are setting option's value as requestMapping of method that is to be invoked.
PS: I haven't tested this code. It's just for reference.
Hope this helps.
Upvotes: 1