ive added the errors to the mav object
Code:
@RequestMapping(value = "/create", method = RequestMethod.GET)
public @ResponseBody ModelAndView createEvent(@ModelAttribute("participant") @Valid Participant participant, BindingResult result, HttpServletResponse response){
ModelAndView mav = new ModelAndView();
validator.validate(participant, result);
if (result.hasErrors()) {
mav.addObject("errors", result.getAllErrors());
mav.setViewName("participant_form");
return mav;
// response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
// return null;
}
// calculate password sha-1 hash
participant.getAccount().setPassword(passwordEncoder.encodePassword(participant.getAccount().getPassword(), null));
// save the participant
Session session = HibernateUtil.getInstance().getCurrentSession();
session.save(participant);
mav.addObject(participant);
return mav;
// return participant;
}
now i can get the errors and distinguish whether everything is oki or not:
Code:
$("#participant_dialog").dialog({
modal: true,
buttons: {
// define the save category handler
"<spring:message code="btn.save"/>": function() {
var obj = $.serializeJSON($("form#participant_form"));
$.getJSON("<c:url value='/participant/create.html' />", obj, function(mav) {
if(mav.modelMap.errors){
alert("error");
}else{
var values = new Array();
values[0] = mav.participant.title;
values[1] = mav.participant.firstName;
values[2] = mav.participant.lastName;
values[3] = mav.participant.email;
values[4] = mav.participant.phone;
var rtn = table.fnAddData(values);
var trAdded = table.fnGetNodes(rtn);
$(trAdded).attr("id", mav.participant.id);
$(trAdded).click(clickRow);
}
});
$(this).dialog("close");
},
// define the cancel dialog handler
"<spring:message code="btn.cancel"/>": function() {
$(this).dialog("close");
}
}
});
But i still dont now how to fill the error tags of the former form...
anybody?