-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hy guys,
since I spent some time to debug a complex page just to find out it was a really minor issue (I left a value empty), I took some time to check....
The following empty values returns different error messages:
<intbox value=""/> java.lang.NumberFormatException: For input string: "" <longbox value=""/> java.lang.NumberFormatException: For input string: "" <decimalbox value=""/> java.lang.NumberFormatException <doublebox value=""/> java.lang.ClassCastException: Unable to find a setter named value that supports
and I could not find anywhere in the documentation that value MUST be specified.
FYI,
be well
Stefano
I think ZK guesses the type of value and try to convert such value to expected type (ie. the property type of the component).
But the empty value has not enough information for guessing. Usually, the type of value will be "String".
Converting "String" to "Integer" (or other numeric types) is illegal in Java.
So, I think that we might not assign "value" property to component if there is no initial value.
For example, just <intbox />.
You can check org.zkoss.lang.Classes.coerce(Class<?>,Object); for more information.
Hope this helps.
Thanks,
I see the point... although could this cause problems if I set the value dynamically by scripting?
<intbox value="${someObject.uncheckedValue}"/>
Maybe ZK team might also refine a bit the exception message and make it the same for all.
Cheers
S
If property value is assigned from a expression, the situation will be a little different.
However, the type of someObject.uncheckedValue normally is same as the type of component's property.
The value doesn't need casting, so, it should be fine,
Asked: 2012-08-28 09:15:37 +0800
Seen: 134 times
Last updated: Aug 31 '12