struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject [s1] Can I have a DynaValidatorBean's Integer property default to null?
Date Fri, 11 Dec 2015 20:17:38 GMT
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


Mime
View raw message