You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Christopher Schultz <ch...@christopherschultz.net> on 2015/12/11 21:17:38 UTC

[s1] Can I have a DynaValidatorBean's Integer property default to null?

All,

Yes, Struts 1.3.10.

I'd like to use a DynaValidatorForm with a property of type
java.lang.Integer. I'd also like to make it a required field. If it were
a String field, I could just say "required" and it would not allow
blank/empty value.

But since this is Integer, it defaults to new java.lang.Integer() which
gives you Zero (as an object). I tried setting initial="null" in the
<form-bean> definition, but of course I got a NumberFormatException
because new Integer("null") fails.

The obvious solutions are to use an intRange to ensure that the value
must be > 0 (which is okay for my use case) or to go back to using a
String value. I'd prefer to use an Integer but configuring for intRange
requires a lot of configuration. (I have a number of fields like this,
so the effort will be multiplied.)

Are there any other options?

Thanks,
-chris

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org