1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.teeda.core.taglib.core; |
17 | |
|
18 | |
import javax.faces.context.FacesContext; |
19 | |
import javax.faces.el.ValueBinding; |
20 | |
import javax.faces.internal.ValueBindingUtil; |
21 | |
import javax.faces.validator.LengthValidator; |
22 | |
import javax.faces.validator.Validator; |
23 | |
import javax.servlet.jsp.JspException; |
24 | |
|
25 | |
import org.seasar.framework.util.AssertionUtil; |
26 | |
import org.seasar.teeda.core.util.BindingUtil; |
27 | |
import org.seasar.teeda.core.util.ConverterUtil; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
public class ValidateLengthTag extends MaxMinValidatorTag { |
34 | |
|
35 | |
private static final long serialVersionUID = 1L; |
36 | |
|
37 | |
private static final String VALIDATOR_ID = LengthValidator.VALIDATOR_ID; |
38 | |
|
39 | 7 | protected int minimum = 0; |
40 | |
|
41 | 7 | protected int maximum = 0; |
42 | |
|
43 | |
public ValidateLengthTag() { |
44 | 7 | super(); |
45 | 7 | } |
46 | |
|
47 | |
protected Validator createValidator() throws JspException { |
48 | 7 | super.setValidatorId(VALIDATOR_ID); |
49 | 7 | LengthValidator validator = (LengthValidator) super.createValidator(); |
50 | 7 | AssertionUtil.assertNotNull("LengthValidator", validator); |
51 | |
|
52 | 6 | evaluateExpressions(); |
53 | 6 | if (isMinimumSet()) { |
54 | 2 | validator.setMinimum(minimum); |
55 | |
} |
56 | 6 | if (isMaximumSet()) { |
57 | 2 | validator.setMaximum(maximum); |
58 | |
} |
59 | 6 | return validator; |
60 | |
} |
61 | |
|
62 | |
private void evaluateExpressions() throws JspException { |
63 | 6 | FacesContext context = FacesContext.getCurrentInstance(); |
64 | 6 | final String min = getMinimum(); |
65 | 6 | if (min != null) { |
66 | 2 | if (BindingUtil.isValueReference(min)) { |
67 | 1 | ValueBinding vb = ValueBindingUtil.createValueBinding(context, |
68 | |
min); |
69 | 1 | minimum = ConverterUtil.convertToInt(vb.getValue(context)); |
70 | |
} else { |
71 | 1 | minimum = ConverterUtil.convertToInt(min); |
72 | |
} |
73 | |
} |
74 | 6 | final String max = getMaximum(); |
75 | 6 | if (max != null) { |
76 | 2 | if (BindingUtil.isValueReference(max)) { |
77 | 1 | ValueBinding vb = context.getApplication().createValueBinding( |
78 | |
max); |
79 | 1 | maximum = ConverterUtil.convertToInt(vb.getValue(context)); |
80 | |
} else { |
81 | 1 | maximum = ConverterUtil.convertToInt(max); |
82 | |
} |
83 | |
} |
84 | 6 | } |
85 | |
|
86 | |
} |