Its normal when i use a DoubleBox in a Editor to edit a double property (RequestFactoryEditorDriver) if i clear the value of the box i get a null pointer exception?
If so how can i validate a DoubleBox with the JSR 303 Validation?
My code looks something like this:
@DecimalMin(value="0.0", message="decimalMin:0.0", groups = {ImpuestoGroup.class, ImpuestoIepsGroup.class})
public double getTasaImpuesto();
<g:DoubleBox ui:field="tasaImpuesto"></g:DoubleBox>
@UiField DoubleBox tasaImpuesto;
When i call the driver.flush() need to check the constraints i have this results:
if i put a value diferent than number i get the on the List the bad value if i put a lower than 0.0 value i can set the constraints to the EditorDriver with driver.setConstraintViolations(constraints);
When i leave blank the field i expect a List with a bad value or the constraint but not a null pointer exception.
The line i get my atention is this one:
Caused by: com.google.gwt.core.client.JavaScriptException: (TypeError) : Cannot read property 'value_0' of null
at Unknown.$doubleValue(http://localhost:9876/proj/C6E66C9FC3DCB1FC08DFFFC07FE049E0.cache.js@21:38447)
Seems that DoubleBox cannot handle the null value.
Please help me. Thank you.
Answered on Google Groups, copied here for convenience:
DoubleBox
uses DoubleParser
. DoubleParser
returns null
if the value is the empty string, and otherwise uses a NumberFormat
, and throws a ParserException
if it cannot parse. Your edited object's property is of type double
, not java.lang.Double
, so when the field is empty, getValue()
returns null
, and the Editor framework tries to unbox the null
to put it into your double
property, hence the NullPointerException
. With any illegal value, DoubleParser
throws; in that case, the ValueBoxEditor
returns the last known value, which explains why it doesn't throw in that case.
Request for enhancement: http://code.google.com/p/google-web-toolkit/issues/detail?id=7783