I have this Controller :
@Controller
@RequestMapping("/path/*")
public class MyController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public String welcomeHandler(final Model model) {
// SOME CODE...
}
@RequestMapping(params = "reloadPage", value = "/", method = RequestMethod.POST)
public String reloadPageHandler(final Model model) {
// SOME CODE...
}
@RequestMapping(params = "search", value = "/", method = RequestMethod.POST)
public String processSubmit(final BindingResult result...)
// SOME CODE...
}
}
and this jsp :
<form:form id="SearchFormController" method="post" modelAttribute="SearchFormBean">
<form:select path="searchCriteria.departmentId">
<form:options items="${addressDepartmentList}" itemValue="id" itemLabel="name" />
</form:select>
<p>
<button type="submit" name="reloadPage">Reload the page</button>
</p>
<form:select path="searchCriteria.cityId">
<form:options items="${addressCityList}" itemValue="id" itemLabel="name" />
</form:select>
<p>
<button type="submit" name="search">Submit</button>
</p>
</form:form>
This code works perfectly fine, when I click on the “Reload the page” button, the reloadPageHandler is called.
Now what I want to achieve, is to remove this button and put an onchange event on my jsp like this :
<form:select path="searchCriteria.departmentId" onchange="submit()">
<form:options items="${addressDepartmentList}" itemValue="id" itemLabel="name" />
</form:select>
The problem here is that when the form is submitted, it’s the “processSubmit” handler that’s called. But I have to call the “reloadPageHandler”.
Any idea on how to do this ? Thanks !
It seems that the reloadPage-parameter is missing. (The former button’s name.)
If you put a hidden field with this name into the form, it should work:
But the problem with this code is still that always the processSubmit-Handler will be called. So a solution could be to change the controller that the reloadPageHandler is only called if reload=true. Then change the onchange to “this.form.reloadPage.value=’true’;submit()”