This is my controller code.
@RequestMapping(value = "/save", method = RequestMethod.POST)
public final String submit(@ModelAttribute("loanType") @Valid LoanType loanType,
BindingResult binding, RedirectAttributes attr, HttpSession session) {
if (binding.hasErrors()) {
attr.addFlashAttribute("org.springframework.validation.BindingResult.loanType",
binding);
attr.addFlashAttribute("loanTypeForm", binding);
return "redirect:/loanType/addLoanType";
}
loanTypeService.insertLoanType(loanType);
log.info("loan type saved succesfully with loan type id =" +
loanType.getLoanTypeId() + " and name =" + loanType.getLoanTypeName());
attr.addFlashAttribute("message", "Loan Type named= '" +
loanType.getLoanTypeName() + "' is added Successfully");
return "redirect:/loanType/listLoanType";
}
This is my view page.
<tr>
<td> </td>
<td><form:input cssErrorClass="errorinput" path="loanTypeName"
alt="LoanTypeName" placeholder="Loan Type Name:" /></td>
<td><form:errors path="loanTypeName" cssClass="error"/>
</td>
</tr>
<tr>
<td> </td>
<td><br>
<table class="form-subtable">
<tr>
<td class="formtitle-subtitle">
Loan Details
</td>
</tr>
<tr>
<td><form:errors path="documents" cssClass="error"/></td>
</tr>
<tr>
<td><form:checkboxes cssClass="regular- checkbox" path="documents"
items="${documentList}" itemLabel="documentName"
itemValue="documentId" delimiter="<br>"/>
</td>
</tr>
</table>
</td>
<td> </td>
</tr>
<tr>
<td></td>
<td>
<br><div class="submit"><input class="submit" type="submit" value="Save" />
<input type="reset" value="Cancel" /></div>
</td>
<td></td>
</tr>
</table>
When I submit the form without filling the text field and only choosing the checkboxes, it shows the error messages but the previoulsy selected checkboxes gets dis-selected...I want them selected when the controller returns the error messages...
Can anyone help me?