Platform: Spring 3.1.2, Tomcat 7.0.30
The issue started after upgraded to Spring 3.1 from 3.0
I have a normal spring enabled form as:
<c:url value='/healthcare/insurance/policy/save' var="url" /> <form:form commandName="insurancePolicy" action="${url }" method="POST" cssClass="form-horizontal"> <div class="module"> <div class="header"> <strong><spring:message code="insurance.policy.view.formbox" /> </strong> </div> <div class="module-content row-fluid"> <div class="span4"> <div class="control-group"> <label class="control-label"><spring:message code="insurance.policy.view.policyId" /></label> <div class="controls"> <form:input path="policyId" cssClass="span10" readonly="true" /> </div> </div> <div class="control-group"> <label class="control-label"><spring:message code="insurance.policy.view.tpaId" /></label> <div class="controls"> <form:select path="tpaId" items="${tpas }" itemLabel="tpaName" itemValue="tpaId" cssClass="span10" /> </div> </div>
And so on.
The way I submit is:
function save(){
$("#insurancePolicy").submit();
}
The way I catch is through the Controller which resides in an abstracted class as below:
public abstract class AbstractCrudViewController<T, PK extends Number, META extends T> extends AbstractViewController {
@SuppressWarnings("unchecked")
@RequestMapping(value="/save", method = RequestMethod.POST)
protected String save(@ModelAttribute T t, Model model, HttpServletRequest request){
logger.debug("Executing save for model: {}", t.toString());
try{
if (getPrimaryKeyValue(t) == null || ((Number) getPrimaryKeyValue(t)).intValue() <=0 ){
logger.debug("Creating new record");
PK pk = getCrudService().create(t);
logger.debug("New record created with ID: {}", pk);
ViewUtil.addSuccess(model, "crud.saveSuccess", request, getPrimaryKeyValue(t));
}
The init binder is declared in the AbstractViewController as:
public abstract class AbstractViewController {
@InitBinder
public void initBinder(WebDataBinder binder) {
String dateFormat = "dd/MM/yyyy";
binder.registerCustomEditor(DateTime.class, new DateTimeEditor(dateFormat,true));
}
}
OK. Now the problem is: I'm saving form and the log says:
DEBUG:com.keype.hawk.hr.mvc.StaffViewController[save]:Executing save for model: Staff [staffId=null, firstName=Steve,, lastName=Harris,, middleName=,, nationality=AF, dob=2012-09-11T00:00:00.000+03:00, status=1000, title=Mr, address1=, address2=, city=, state=, postalCode=, country=AF, homePhoneAreaCode=, homePhone=,, homePhoneExt=, homePhoneAllowSoliciation=, workPhoneAreaCode=, workPhone=null, workPhoneExt=, workPhoneAllowSoliciation=, fax=, mobileAreaCode=, mobile=, mobileAllowSolicitation=, email=null, joiningDate=null, gender=, govtId=, maritalStatus=, passportNumber=, passportExpiryDate=null, totalWorkExperience=, notes=, staffCreated=null, staffModified=null, dateCreated=null, dateModified=null]
Notice the comma after each field.
For debugging, I serialized the form using jquery serialize and checked and there NO comma with it. Then ajax-posted this data to the server and after @ModelAttribute did it's job, The comma gets appended.
Any idea? Something with Init binder?