1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.taglib.core;
20
21 import javax.el.ELContext;
22 import javax.el.ValueExpression;
23 import javax.faces.context.FacesContext;
24 import javax.faces.validator.Validator;
25 import javax.servlet.jsp.JspException;
26
27
28
29
30
31
32
33
34 public abstract class GenericMinMaxValidatorTag<T>
35 extends ValidatorTag
36 {
37 protected ValueExpression _minimum;
38 protected ValueExpression _maximum;
39 protected T _min = null;
40 protected T _max = null;
41
42 public void setMinimum(ValueExpression minimum)
43 {
44 _minimum = minimum;
45 }
46
47 public void setMaximum(ValueExpression maximum)
48 {
49 _maximum = maximum;
50 }
51
52 public void release()
53 {
54 _minimum = null;
55 _maximum = null;
56 _min = null;
57 _max = null;
58 }
59
60
61
62
63
64
65
66
67 protected Validator createValidator() throws JspException
68 {
69 if (null == _minimum && null == _maximum){
70 throw new JspException("a minimum and / or a maximum have to be specified");
71 }
72 ELContext elContext = FacesContext.getCurrentInstance().getELContext();
73 if (null != _minimum){
74 _min = getValue(_minimum.getValue(elContext));
75 }
76 if (null != _maximum){
77 _max = getValue(_maximum.getValue(elContext));
78 }
79 if (null != _minimum && null != _maximum){
80 if (!isMinLTMax()){
81 throw new JspException("maximum limit must be greater than the minimum limit");
82 }
83 }
84 return super.createValidator();
85 }
86
87
88
89
90 protected abstract boolean isMinLTMax();
91
92
93
94
95
96
97 protected abstract T getValue(Object value);
98 }