View Javadoc

1   // Copyright 2006 Daniel Gredler
2   //
3   // Licensed under the Apache License, Version 2.0 (the "License");
4   // you may not use this file except in compliance with the License.
5   // You may obtain a copy of the License at
6   //
7   //     http://www.apache.org/licenses/LICENSE-2.0
8   //
9   // Unless required by applicable law or agreed to in writing, software
10  // distributed under the License is distributed on an "AS IS" BASIS,
11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  // See the License for the specific language governing permissions and
13  // limitations under the License.
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.Min;
20  import org.apache.tapestry.valid.ValidatorException;
21  
22  /***
23   * Subclass of the {@link Min} 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 StringMin extends Min {
31  
32      public final static String NAME = "smin";
33  
34      public StringMin() {
35          super();
36      }
37  
38      public StringMin( 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 setSmin( double smin ) {
52          super.setMin( smin );
53      }
54  
55  }