litesoft
Diff Revisions
947
vs
948
for /trunk/GWT_Sandbox/FormEngine/src/com/temp/shared/validators/MaxLengthValueValidator.java
|
@@ -5,33 +5,27 @@ |
5 |
5 |
|
import com.temp.shared.*; |
6 |
6 |
|
import com.temp.shared.utils.*; |
7 |
7 |
|
|
8 |
|
- |
public class MaxLengthValueValidator implements ValueValidator |
9 |
|
- |
{ |
|
8 |
+ |
public class MaxLengthValueValidator implements ValueValidator { |
10 |
9 |
|
public static final String TEMPLATE_ID_CODE = "TooLong"; |
11 |
10 |
|
public static final String USER_DATA_MAX_LENGTH = "maxLength"; |
12 |
11 |
|
public static final String USER_DATA_CURRENT_LENGTH = "currentLength"; |
13 |
12 |
|
|
14 |
13 |
|
private final int maxLength; |
15 |
14 |
|
|
16 |
|
- |
public MaxLengthValueValidator( int maxLength ) |
17 |
|
- |
{ |
|
15 |
+ |
public MaxLengthValueValidator( int maxLength ) { |
18 |
16 |
|
this.maxLength = Validate.length( "maxLength", maxLength ); |
19 |
17 |
|
} |
20 |
18 |
|
|
21 |
19 |
|
@Override |
22 |
|
- |
public E13nData checkValue( Object value ) |
23 |
|
- |
{ |
24 |
|
- |
if ( value instanceof String ) |
25 |
|
- |
{ |
|
20 |
+ |
public E13nData checkValue( Object value ) { |
|
21 |
+ |
if ( value instanceof String ) { |
26 |
22 |
|
return checkString( value.toString().trim() ); |
27 |
23 |
|
} |
28 |
24 |
|
return null; // OK! |
29 |
25 |
|
} |
30 |
26 |
|
|
31 |
|
- |
protected E13nData checkString( String userData ) |
32 |
|
- |
{ |
33 |
|
- |
if ( userData.length() > maxLength ) |
34 |
|
- |
{ |
|
27 |
+ |
protected E13nData checkString( String userData ) { |
|
28 |
+ |
if ( userData.length() > maxLength ) { |
35 |
29 |
|
return new E13nData( TEMPLATE_ID_CODE )// |
36 |
30 |
|
.addSubstitutionNamedUserData( USER_DATA_MAX_LENGTH, Integer.toString( maxLength ) ) // |
37 |
31 |
|
.addSubstitutionNamedUserData( USER_DATA_CURRENT_LENGTH, Integer.toString( userData.length() ) ); |