1 | |
package org.seasar.cubby.validator.validators; |
2 | |
|
3 | |
import org.seasar.cubby.validator.BaseValidator; |
4 | |
import org.seasar.cubby.validator.ValidationContext; |
5 | |
import org.seasar.framework.util.StringUtil; |
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
public class RequiredValidator extends BaseValidator { |
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
public RequiredValidator() { |
19 | 16 | this("valid.required"); |
20 | 16 | } |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | 16 | public RequiredValidator(final String messageKey) { |
27 | 16 | this.setMessageKey(messageKey); |
28 | 16 | } |
29 | |
|
30 | |
public String validate(final ValidationContext ctx) { |
31 | 8 | final Object value = ctx.getValue(); |
32 | 8 | if (value instanceof String) { |
33 | 4 | String str = (String)value; |
34 | 4 | if (!StringUtil.isEmpty(str)) { |
35 | 4 | return null; |
36 | |
} |
37 | |
} else if (value != null) { |
38 | 1 | return null; |
39 | |
} |
40 | 3 | return getMessage(getPropertyMessage(ctx |
41 | |
.getName())); |
42 | |
} |
43 | |
|
44 | |
} |