Announcement Announcement Module
Collapse
No announcement yet.
BindException while using Spring Conversion Service to convert from String to int Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • BindException while using Spring Conversion Service to convert from String to int

    Dear all,

    I am using ConnectionService in my Spring MVC project. I have domain object with one column as 'int' and this domain object is used as command object to form.

    However, my webserver throws below error, when i try to submit the form data. Here is the error,


    org.springframework.web.util.NestedServletExceptio n: Request processing failed; nested exception is org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBinding Result: 1 errors
    Field error in object 'boutiqueNew' on field 'telephone': rejected value [9000766605]; codes [typeMismatch.boutiqueNew.telephone,typeMismatch.te lephone,typeMismatch.int,typeMismatch]; arguments [org.springframework.context.support.DefaultMessage SourceResolvable: codes [boutiqueNew.telephone,telephone]; arguments []; default message [telephone]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'telephone'; nested exception is java.lang.NumberFormatException: For input string: "9000766605"]
    org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:894)
    org.springframework.web.servlet.FrameworkServlet.d oPost(FrameworkServlet.java:789)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:754)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:847)
    root cause

    org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBinding Result: 1 errors
    Field error in object 'boutiqueNew' on field 'telephone': rejected value [9000766605]; codes [typeMismatch.boutiqueNew.telephone,typeMismatch.te lephone,typeMismatch.int,typeMismatch]; arguments [org.springframework.context.support.DefaultMessage SourceResolvable: codes [boutiqueNew.telephone,telephone]; arguments []; default message [telephone]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'telephone'; nested exception is java.lang.NumberFormatException: For input string: "9000766605"]
    org.springframework.web.method.annotation.ModelAtt ributeMethodProcessor.resolveArgument(ModelAttribu teMethodProcessor.java:110)
    org.springframework.web.method.support.HandlerMeth odArgumentResolverComposite.resolveArgument(Handle rMethodArgumentResolverComposite.java:74)
    org.springframework.web.method.support.InvocableHa ndlerMethod.getMethodArgumentValues(InvocableHandl erMethod.java:155)
    org.springframework.web.method.support.InvocableHa ndlerMethod.invokeForRequest(InvocableHandlerMetho d.java:117)
    org.springframework.web.servlet.mvc.method.annotat ion.ServletInvocableHandlerMethod.invokeAndHandle( ServletInvocableHandlerMethod.java:96)
    org.springframework.web.servlet.mvc.method.annotat ion.RequestMappingHandlerAdapter.invokeHandlerMeth od(RequestMappingHandlerAdapter.java:617)
    org.springframework.web.servlet.mvc.method.annotat ion.RequestMappingHandlerAdapter.handleInternal(Re questMappingHandlerAdapter.java:578)
    org.springframework.web.servlet.mvc.method.Abstrac tHandlerMethodAdapter.handle(AbstractHandlerMethod Adapter.java:80)
    org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:900)
    org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:827)
    org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:882)
    org.springframework.web.servlet.FrameworkServlet.d oPost(FrameworkServlet.java:789)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:754)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:847)


    Here is my Spring ConversionService configuration,
    <mvc:annotation-driven conversion-service="conversionService"/>
    <bean id="conversionService" class="org.springframework.context.support.Convers ionServiceFactoryBean">
    <property name="converters">
    <list>
    <bean class="org.netvogue.server.webmvc.converters.Bouti queConverter" />
    </list>
    </property>
    </bean>

    Here is my domain object,


    public class BoutiqueNew {

    private String email;
    private String password;
    private int zip;
    private int telephone;
    private String website;
    }

    As per the spring reference documentation, connectionservice must do few default conversions itself without the necessity of customConverters. However, in my case it is not doing so.

    Could you please help me with this? Or Is Custom implementation of conversion mandatory here?
    Any help would be greatly appreciated.

    Thanks,
    Abdul
Working...
X