Achinta - 2014-11-20

Hi All,

This is Achinta, a new bee in the world of Spring. I need a small help to understand and resolve a problem which I am facing. I hope will find my answer here.

I am working on a sample Spring Web project. Here I have a Controller, Bean class and a Jsp page for UI and the other artifacts. Here is my Bean class.

@Entity
@Table(name = "tblLoadCriteria")
public class Load implements Serializable {
    private Integer loadID;
    private String loadCountry;
    private String loadState;
    private String loadCity;
    private Integer totalAirVolume;

    public Load() {//Constructor}

   //And Getter & Setter methods for loadID, loadCountry, loadState, loadCity & totalAirVolume
}

And the Spring form in my Jsp page.

<form:form id="systemForm" commandName="load" action="${pageContext.request.contextPath}/doSothing" method="POST" >
  <spring:message code="loadCountry" />: <form:input path="loadCountry" />
  <spring:message code="loadState" />: <form:input path="loadState" />
  <spring:message code="loadCity" />: <form:input path="loadCity" />
  <spring:message code="totalAirVolume" />: <form:input path="totalAirVolume" />

  <spring:message code="save" text="Save" scope="page" var="save" />
  <input id="next" type="button" onClick="submitSave();" />
</form:form>

And here goes the controller code

@RequestMapping(value = "/doSothing", method = RequestMethod.POST)
public String doSothing(HttpServletRequest request, HttpServletResponse response, @ModelAttribute("load") @Valid Load load ,
            BindingResult result, SessionStatus sessionStatus) {

    loadService.saveLoad(load);

    return "forward:getApplicationRequirements";
}

Here the problem I am facing is, The "totalAirVolume" in the Load bean class is of type Integer and is bind to the UI page using spring form tags. But in the UI if I enter float value (F.Ex 12.12), instead of an integer it gives me status:400 error.

I am not so keen on javascript for validation for "totalAirVolume" field and looking for Spring way to handle it. Please help.

Your responses are highly appreciated.

Regards
Achinta