Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
DateField |
|
| 1.5;1.5 |
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 java.text.DateFormat; | |
18 | import java.util.Date; | |
19 | ||
20 | import org.apache.tapestry.valid.DateValidator; | |
21 | import org.apache.tapestry.valid.IValidator; | |
22 | import org.apache.tapestry.valid.ValidField; | |
23 | ||
24 | /** | |
25 | * Backwards compatible version of the 1.0.7 DateField component. <table border=1> | |
26 | * <tr> | |
27 | * <td>Parameter</td> | |
28 | * <td>Type</td> | |
29 | * <td>Read / Write</td> | |
30 | * <td>Required</td> | |
31 | * <td>Default</td> | |
32 | * <td>Description</td> | |
33 | * </tr> | |
34 | * <tr> | |
35 | * <td>date</td> | |
36 | * <td>java.util.Date</td> | |
37 | * <td>R / W</td> | |
38 | * <td>yes</td> | |
39 | * <td> </td> | |
40 | * <td>The date property to edit.</td> | |
41 | * </tr> | |
42 | * <tr> | |
43 | * <td>required</td> | |
44 | * <td>boolean</td> | |
45 | * <td>R</td> | |
46 | * <td>no</td> | |
47 | * <td>no</td> | |
48 | * <td>If true, then a value must be entered.</td> | |
49 | * </tr> | |
50 | * <tr> | |
51 | * <td>minimum</td> | |
52 | * <td>java.util.Date</td> | |
53 | * <td>R</td> | |
54 | * <td>no</td> | |
55 | * <td> </td> | |
56 | * <td>If provided, the date entered must be equal to or later than the provided minimum date. | |
57 | * </td> | |
58 | * </tr> | |
59 | * <tr> | |
60 | * <td>maximum</td> | |
61 | * <td>java.util.Date</td> | |
62 | * <td>R</td> | |
63 | * <td>no</td> | |
64 | * <td> </td> | |
65 | * <td>If provided, the date entered must be less than or equal to the provided maximum date.</td> | |
66 | * </tr> | |
67 | * <tr> | |
68 | * <td>displayName</td> | |
69 | * <td>String</td> | |
70 | * <td>R</td> | |
71 | * <td>yes</td> | |
72 | * <td> </td> | |
73 | * <td>A textual name for the field that is used when formulating error messages.</td> | |
74 | * </tr> | |
75 | * <tr> | |
76 | * <td>format</td> | |
77 | * <td>{@link DateFormat}</td> | |
78 | * <td>R</td> | |
79 | * <td>no</td> | |
80 | * <td>Default format <code>MM/dd/yyyy</code></td> | |
81 | * <td>The format used to display and parse dates.</td> | |
82 | * </tr> | |
83 | * <tr> | |
84 | * <td>displayFormat</td> | |
85 | * <td>{@link String}</td> | |
86 | * <td>R</td> | |
87 | * <td>no</td> | |
88 | * <td><code>MM/DD/YYYY</code></td> | |
89 | * <td>The format string presented to the user if the date entered is in an incorrect format. e.g. | |
90 | * the format object throws a ParseException.</td> | |
91 | * </tr> | |
92 | * </table> | |
93 | * <p> | |
94 | * Informal parameters are allowed. A body is not allowed. | |
95 | * | |
96 | * @author Howard Lewis Ship, Richard Lewis-Shell | |
97 | * @since 1.0.8 | |
98 | * @see ValidField | |
99 | */ | |
100 | ||
101 | 0 | public abstract class DateField extends ValidField |
102 | { | |
103 | public abstract Date getDate(); | |
104 | ||
105 | public abstract void setDate(Date date); | |
106 | ||
107 | public abstract Date getMinimum(); | |
108 | ||
109 | public abstract Date getMaximum(); | |
110 | ||
111 | public abstract boolean isRequired(); | |
112 | ||
113 | public abstract DateFormat getFormat(); | |
114 | ||
115 | public abstract String getDisplayFormat(); | |
116 | ||
117 | /** | |
118 | * Overrides {@link ValidField#getValidator()}to construct a validator on-the-fly. | |
119 | */ | |
120 | ||
121 | public IValidator getValidator() | |
122 | { | |
123 | 0 | DateValidator validator = new DateValidator(); |
124 | ||
125 | 0 | if (isParameterBound("minimum")) |
126 | 0 | validator.setMinimum(getMinimum()); |
127 | ||
128 | 0 | if (isParameterBound("maximum")) |
129 | 0 | validator.setMaximum(getMaximum()); |
130 | ||
131 | 0 | if (isParameterBound("required")) |
132 | 0 | validator.setRequired(isRequired()); |
133 | ||
134 | 0 | if (isParameterBound("format")) |
135 | 0 | validator.setFormat(getFormat()); |
136 | ||
137 | 0 | if (isParameterBound("displayFormat")) |
138 | 0 | validator.setDisplayFormat(getDisplayFormat()); |
139 | ||
140 | 0 | return validator; |
141 | } | |
142 | ||
143 | /** | |
144 | * @see org.apache.tapestry.valid.ValidField#getValue() | |
145 | */ | |
146 | public Object getValue() | |
147 | { | |
148 | 0 | return getDate(); |
149 | } | |
150 | ||
151 | /** | |
152 | * @see org.apache.tapestry.valid.ValidField#setValue(java.lang.Object) | |
153 | */ | |
154 | public void setValue(Object value) | |
155 | { | |
156 | 0 | setDate((Date) value); |
157 | 0 | } |
158 | ||
159 | } |