Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ValidatingTextField |
|
| 1.2857142857142858;1.286 |
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.StringValidator; | |
19 | import org.apache.tapestry.valid.ValidField; | |
20 | ||
21 | /** | |
22 | * Backwards compatible version of the 1.0.7 ValidatingTextField component. | |
23 | * <table 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>text</td> | |
34 | * <td>java.lang.String</td> | |
35 | * <td>R / W</td> | |
36 | * <td>yes</td> | |
37 | * <td> </td> | |
38 | * <td>The text inside the text field. | |
39 | * <p> | |
40 | * When the form is submitted, the binding is only updated if the value is | |
41 | * valid.</td> | |
42 | * </tr> | |
43 | * <tr> | |
44 | * <td>minimumLength</td> | |
45 | * <td>int</td> | |
46 | * <td>R</td> | |
47 | * <td>no</td> | |
48 | * <td>0</td> | |
49 | * <td>The minimum length (number of characters read) for the field. The value | |
50 | * provided in the request is trimmed of leading and trailing whitespace. | |
51 | * <p> | |
52 | * If a field is not required and no value is given, then minimumLength is | |
53 | * ignored. Minimum length only applies if <em>some</em> non-null value is | |
54 | * given.</td> | |
55 | * </tr> | |
56 | * <tr> | |
57 | * <td>required</td> | |
58 | * <td>boolean</td> | |
59 | * <td>R</td> | |
60 | * <td>no</td> | |
61 | * <td>false</td> | |
62 | * <td>If true, then a non-null value must be provided. A value consisting only | |
63 | * of whitespace is considered null.</td> | |
64 | * </tr> | |
65 | * <tr> | |
66 | * <td>displayName</td> | |
67 | * <td>String</td> | |
68 | * <td>R</td> | |
69 | * <td>yes</td> | |
70 | * <td> </td> | |
71 | * <td>A textual name for the field that is used when formulating error | |
72 | * messages.</td> | |
73 | * </tr> | |
74 | * </table> | |
75 | * <p> | |
76 | * May not have a body. May have informal parameters. | |
77 | * | |
78 | * @author Howard Lewis Ship | |
79 | * @since 1.0.8 | |
80 | * @see org.apache.tapestry.valid.ValidField | |
81 | */ | |
82 | ||
83 | 0 | public abstract class ValidatingTextField extends ValidField |
84 | { | |
85 | ||
86 | public abstract int getMinimumLength(); | |
87 | ||
88 | public abstract boolean isRequired(); | |
89 | ||
90 | public abstract String getText(); | |
91 | ||
92 | public abstract void setText(String value); | |
93 | ||
94 | /* | |
95 | * (non-Javadoc) | |
96 | * | |
97 | * @see org.apache.tapestry.valid.ValidField#getValue() | |
98 | */ | |
99 | public Object getValue() | |
100 | { | |
101 | 0 | return getText(); |
102 | } | |
103 | ||
104 | /* | |
105 | * (non-Javadoc) | |
106 | * | |
107 | * @see org.apache.tapestry.valid.ValidField#setValue(java.lang.Object) | |
108 | */ | |
109 | public void setValue(Object value) | |
110 | { | |
111 | 0 | setText((String) value); |
112 | 0 | } |
113 | ||
114 | /** | |
115 | * Overrides {@link ValidField#getValidator()}to construct a validator on | |
116 | * the fly. | |
117 | */ | |
118 | public IValidator getValidator() | |
119 | { | |
120 | 0 | StringValidator validator = new StringValidator(); |
121 | ||
122 | 0 | if (isParameterBound("required")) validator.setRequired(isRequired()); |
123 | ||
124 | 0 | if (isParameterBound("minimumLength")) |
125 | 0 | validator.setMinimumLength(getMinimumLength()); |
126 | ||
127 | 0 | return validator; |
128 | } | |
129 | } |