suppose i hava two view files(jsp
s) and one class(BudgetControlRegisterDto
)
BudgetControlRegisterDto
public class BudgetControlRegisterDto implements Serializable {
@NotNull(message = "{NotNull.java.util.Date}")
private Date demandReceiveDate;
@NotNull(message = "{NotNull.java.util.Date}")
private Date demandOriginalDate;
@NotNull(message = "Start date {NotNull.java.util.Date}")
private Date startDate;
@NotNull(message = "End date {NotNull.java.util.Date}")
private Date endDate;
// setter and getter
}
In one view file i want to validate startDate
and endDate
and in other view file i want to validate demandOriginalDate
and demandReceiveDate
using json ajax. when validation occurs i get validation message for all fields with below code:
controller class's method this is testing code used by both view files(jsp
s)
@RequestMapping(value = "/addnewdemand.json", method = RequestMethod.POST)
public @ResponseBody BudgetControlRegisterDto addNewDemand(@Valid @ModelAttribute("bcrDto") BudgetControlRegisterDto bcrDto,Errors errors){
log.info("addNewDemand invoked!");
if(errors.hasErrors()) {
log.info("has errors");
bcrDto.setFieldsErrors(errors.getFieldErrors());
return bcrDto;
}
return bcrDto;
}
.js file this is testing code used by both view files(jsp
s) below code is ajax response code
if(response.fieldsErrors != null) {
html ='<div class="ui-message-error">';
for(var i= 0; i<response.fieldsErrors.length; i++) {
html+='<span>'+response.fieldsErrors[i].defaultMessage+'</span><br/>';
}
html+='</div>';
$("#bcrForm_message").html(html);
}
Question why m i getting validation message of all fields