Results 1 to 2 of 2

Thread: BindException while trying to bind empty form field to float (primitiv)

  1. #1
    Join Date
    Jan 2013
    Posts
    4

    Default BindException while trying to bind empty form field to float (primitiv)

    Hi,

    As it's in the title, I get a BindException, trying to validate a form field:

    Model:
    Code:
    public abstract class AbstractMaterial {
       
       // auto generated
       private float volume;
    }
    View:
    Code:
    <c:forEach items="${helper.materials}" var="material" varStatus="loop">
    
         <td><form:input path="materials[${loop.index}].volume"/></td>
    
    </c:forEach>
    Controller:
    Code:
    @InitBinder
    protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder){	
       binder.registerCustomEditor(Date.class, new CustomDateEditor(SystemGlobals.europeDateFormat, true));		
       binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));		
    }

    Exception:
    Code:
    Field error in object 'helper' on field 'materials[0].volume': rejected value []; codes [typeMismatch.helper.materials[0].volume,typeMismatch.helper.materials.volume,typeMismatch.materials[0].volume,typeMismatch.materials.volume,typeMismatch.volume,typeMismatch.float,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [helper.materials[0].volume,materials[0].volume]; arguments []; default message [materials[0].volume]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'float' for property 'materials[0].volume'; nested exception is java.lang.NumberFormatException: empty String]
    I use spring only since a short time and therefore I am very grateful for any help.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    And your problem is? YOu are using a primitive a primitive cannot be null so an empty string cannot be converted...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •