[Stripes-users] Range checking validation

Subject:   [Stripes-users] Range checking validation (find more)
From:   Tim Fennell <hidden> (find more)
Date:   Dec 04, 2005 08:52

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:

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,


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!
Stripes-users mailing list
Entire Thread (Showing 3 of 4)

  • [Stripes-users] Range checking validation Tim Fennell <hidden>
    • Re: [Stripes-users] Range checking validation Sean Blezard <hidden>

      Hi, I think the virtue of Stripes is its simplicity and elegance in dealing with common business problems. My suggestion would be to go for the simple typesafe approach numbers are the values that are most likely to have static validation rules, rather than data ...

    • Re: [Stripes-users] Range checking validation Nic Holbrook <hidden>

      I know we have brought this up before, but I think some of the more complex validations should just be handed over to the user. If we implement the Validatable interface, we should be responsible for the more complex validations. Have you ... (1 more message in this thread)