Getting rejected value null spring validation
Posted
by
Shabarinath
on Stack Overflow
See other posts from Stack Overflow
or by Shabarinath
Published on 2014-06-01T21:22:35Z
Indexed on
2014/06/01
21:24 UTC
Read the original article
Hit count: 157
Hi in my project when I am trying to validate my form its not showing any error messages even if validation fails (Event Form is not submitted and enters into validation fail block)
Here is my code
/****************** Post Method *************/
@RequestMapping(value="/property", method = RequestMethod.POST)
public String saveOrUpdateProperty(@ModelAttribute("property") Property property,
BindingResult result,
Model model,
HttpServletRequest request) throws Exception {
try {
if(validateFormData(property, result)) {
model.addAttribute("property", new Property());
return "property/postProperty";
}
}
/********* Validate Block *************/
private boolean validateFormData(Property property, BindingResult result) throws DaoException {
if (property.getPropertyType() == null || property.getPropertyType().equals("")) {
result.rejectValue("propertyType", "Cannot Be Empty !", "Cannot Be Empty !");
}
if (property.getTitle() == null || property.getTitle().equals("")) {
result.rejectValue("title", "Cannot Be Empty !", "Cannot Be Empty !");
}
return (result.hasFieldErrors() || result.hasErrors());
}
But when i debug i can see below one
org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'property' on field 'title': rejected value [null]; codes [Cannot Be Empty !.property.title,Cannot Be Empty !.title,Cannot Be Empty !.java.lang.String,Cannot Be Empty !]; arguments []; default message [Cannot Be Empty !]
and this is how i am displaying in jsp file
<div class="control-group">
<div class="controls">
<label class="control-label"><span class="required">* </span>Property Type</label>
<div class="controls">
<form:input path="title" placeholder="Pin Code" cssClass="form-control border-radius-4 textField"/>
<form:errors path="title" style="color:red;"/>
</div>
</div>
</div>
Event though when i see the below one when i debug (1 Error its correct)
org.springframework.validation.BeanPropertyBindingResult: 1 errors
Why it is not displayed in jsp can any one hep me?
© Stack Overflow or respective owner