Announcement Announcement Module
Collapse
No announcement yet.
BindException while trying to bind empty form field to float (primitiv) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    And your problem is? YOu are using a primitive a primitive cannot be null so an empty string cannot be converted...

    Comment

    Working...
    X