Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
NumericField |
|
| 1.8;1.8 |
1 | // Copyright 2004, 2005 The Apache Software Foundation | |
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 org.apache.tapestry.contrib.valid; | |
16 | ||
17 | import org.apache.tapestry.valid.IValidator; | |
18 | import org.apache.tapestry.valid.NumberValidator; | |
19 | import org.apache.tapestry.valid.ValidField; | |
20 | ||
21 | /** | |
22 | * Backwards compatible version of the 1.0.7 NumericField component. <table | |
23 | * border=1> | |
24 | * <tr> | |
25 | * <td>Parameter</td> | |
26 | * <td>Type</td> | |
27 | * <td>Read / Write</td> | |
28 | * <td>Required</td> | |
29 | * <td>Default</td> | |
30 | * <td>Description</td> | |
31 | * </tr> | |
32 | * <tr> | |
33 | * <td>value</td> | |
34 | * <td>{@link Number}</td> | |
35 | * <td>R / W</td> | |
36 | * <td>yes</td> | |
37 | * <td> </td> | |
38 | * <td>The value to be updated. | |
39 | * <p> | |
40 | * When the form is submitted, this parameter is only updated if the value is | |
41 | * valid. | |
42 | * <p> | |
43 | * When rendering, a null value will render as the empty string. A value of zero | |
44 | * will render normally. | |
45 | * <p> | |
46 | * When the form is submitted, the type of the binding is used to determine what | |
47 | * kind of object to convert the string to.</td> | |
48 | * </tr> | |
49 | * <tr> | |
50 | * <td>minimum</td> | |
51 | * <td>{@link Number}</td> | |
52 | * <td>R</td> | |
53 | * <td>no</td> | |
54 | * <td> </td> | |
55 | * <td>The minimum value accepted for the field.</td> | |
56 | * </tr> | |
57 | * <tr> | |
58 | * <td>maximum</td> | |
59 | * <td>{@link Number}</td> | |
60 | * <td>R</td> | |
61 | * <td>no</td> | |
62 | * <td> </td> | |
63 | * <td>The maximum value accepted for the field.</td> | |
64 | * </tr> | |
65 | * <tr> | |
66 | * <td>required</td> | |
67 | * <td>boolean</td> | |
68 | * <td>R</td> | |
69 | * <td>no</td> | |
70 | * <td>false</td> | |
71 | * <td>If true, then a non-null value must be provided. If the field is not | |
72 | * required, and a null (all whitespace) value is supplied in the field, then | |
73 | * the value parameter is <em>not</em> updated.</td> | |
74 | * </tr> | |
75 | * <tr> | |
76 | * <td>displayName</td> | |
77 | * <td>String</td> | |
78 | * <td>R</td> | |
79 | * <td>yes</td> | |
80 | * <td> </td> | |
81 | * <td>A textual name for the field that is used when formulating error | |
82 | * messages.</td> | |
83 | * </tr> | |
84 | * <tr> | |
85 | * <td>type</td> | |
86 | * <td>String</td> | |
87 | * <td>R</td> | |
88 | * <td>yes</td> | |
89 | * <td> </td> | |
90 | * <td>The class name used to convert the value entered. See | |
91 | * {@link NumberValidator#setValueType(String)}</td> | |
92 | * </tr> | |
93 | * </table> | |
94 | * <p> | |
95 | * May not contain a body. May have informal parameters. | |
96 | * | |
97 | * @author Howard Lewis Ship | |
98 | * @since 1.0.8 | |
99 | * @see ValidField | |
100 | */ | |
101 | ||
102 | 0 | public abstract class NumericField extends ValidField |
103 | { | |
104 | ||
105 | public abstract Number getMinimum(); | |
106 | ||
107 | public abstract Number getMaximum(); | |
108 | ||
109 | public abstract boolean isRequired(); | |
110 | ||
111 | public abstract String getType(); | |
112 | ||
113 | /** | |
114 | * Overrides {@link ValidField#getValidator()}to construct a validator on | |
115 | * the fly. | |
116 | */ | |
117 | ||
118 | public IValidator getValidator() | |
119 | { | |
120 | 0 | NumberValidator validator = new NumberValidator(); |
121 | ||
122 | 0 | if (isParameterBound("minimum")) validator.setMinimum(getMinimum()); |
123 | ||
124 | 0 | if (isParameterBound("maximum")) validator.setMaximum(getMaximum()); |
125 | ||
126 | 0 | if (isParameterBound("required")) validator.setRequired(isRequired()); |
127 | ||
128 | 0 | if (isParameterBound("type")) validator.setValueType(getType()); |
129 | ||
130 | 0 | return validator; |
131 | } | |
132 | } |