Friday, 6 September 2013

why my spring validation annotations doesnt work

why my spring validation annotations doesnt work

i have simple for where i put one string and im using annotations to valid
the value and it doesnt work
here is my class:
public class Destination
{
@NotNull
String address;
public Destination(){}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
here is my controller method
@RequestMapping(value = "/search", method = RequestMethod.POST) public
String findDestination(@ModelAttribute("destination") @Valid Destination
destination, BindingResult result, RedirectAttributes redirectAttrs) {
if(result.hasErrors()) { return "redirect:/"; } Location location =
LocationManager.getLocation(destination.getAddress()); Weather weather =
WeatherManager.getWeather(location);
redirectAttrs.addFlashAttribute("weather", weather);
redirectAttrs.addFlashAttribute("location", location); return
"redirect:/"; }
and hre is my form in jsp file:
<form:form method="post" action="search" commandName="destination"
class="form-horizontal">
<div class="control-group">
<div class="controls">
<form:input path="address" placeholder="Enter destination
address"/>
<form:errors path="address" cssclass="error"></form:errors>
<input type="submit" value="Search" class="btn"/>
</form:form>
</div>
</div>
so the problem is that it doesnt valid my input when i left it empty it
still try to get addres for location object from null destination object
and i get the exception HTTP Status 500 - Request processing failed;
nested exception is java.util.NoSuchElementException

No comments:

Post a Comment