1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package net.sf.beanform.validator;
16
17 import org.apache.tapestry.form.IFormComponent;
18 import org.apache.tapestry.form.ValidationMessages;
19 import org.apache.tapestry.form.validator.Max;
20 import org.apache.tapestry.valid.ValidatorException;
21
22 /***
23 * Subclass of the {@link Max} validator that doesn't barf all over the
24 * place if it's handed a string instead of a number. Apparently Tapestry
25 * normally does some automatic type conversions depending on a value's
26 * setter and getter, but our setters and getters are for generic objects.
27 *
28 * @author Daniel Gredler
29 */
30 public class StringMax extends Max {
31
32 public final static String NAME = "smax";
33
34 public StringMax() {
35 super();
36 }
37
38 public StringMax( String initializer ) {
39 super( initializer );
40 }
41
42 @Override
43 public void validate( IFormComponent field, ValidationMessages messages, Object object )
44 throws ValidatorException {
45 if( object instanceof String ) {
46 object = Double.parseDouble( (String) object );
47 }
48 super.validate( field, messages, object );
49 }
50
51 public void setSmax( double smax ) {
52 super.setMax( smax );
53 }
54
55 }