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.