Hey Everyone,
It seems that one kind of validation that isn't currently provided by
Stripes, but is quite common, is range checking. E.g. check that a
field value is between 1 and 100 etc. I've punted on this before
primarily because the restrictions annotation properties makes it
hard to come up with a clean, universal solution to this. My desire
had been to make it possible to do range checking on any type that
implements Comparable, not just on numbers. This would include
things like Strings, Dates etc.
The way I see it is that there are basically two alternatives. The
first would be to implement this just for numbers, and the annotation
would be completely type-safe, e.g.:
@Validate(minvalue=0, maxvalue=120)
public long getAge() { ... }
The other option would be to implement it for any type that
implements Comparable. This would be significantly more complex, so
I'd like to make sure that it's worthwhile before investing too much
time in it. In this case the validation might look like this:
@Validate(minvalue="1/1/1900")
public Date getBirthday() ...
@Validate(minvalue="0", maxvalue="120")
public long getAge() ...
Notice the quotes around the values in this case. How I would see
this working is that the quoted value would get converted to the same
type as the property, using the Stripes type conversion system. Then
compareTo() would be used to ensure that the field value was greater
than the minimum supplied, and less than the max supplied etc. The
downside to this approach is that it makes it possible to screw up
the annotation and put junk in the min/maxvalue attributes.
I'd appreciate any feedback on this. Is it worth adding the extra
complexity of the second option? I'm not worried about coding it in
Stripes so much as making it easier for users of Stripes to run into
errors. Cheers,
-t
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Stripes-users mailing list
hidden
https://lists.sourceforge.net/lists/listinfo/stripes-users