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