1

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?

4

2 回答 2

24

I was experiencing the same issue, but Twitter Bootstrap wasn't the cause.

In my case, we had 2 inputs having the same name attribute. In that case, data for this two input are sent as an Array. Since my inputs were empty, the array was myName=,

于 2012-12-04T16:06:42.387 回答
-2

Problem Isolated. It seems like Twitter Bootstrap is creating the problem. There was a Tab inside the form. I put the tab outside the form and the problem is solved. Extremely strange.

于 2012-09-14T12:28:03.860 回答