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> extends ValidatorTag
35 {
36 protected ValueExpression _minimum;
37 protected ValueExpression _maximum;
38 protected T _min = null;
39 protected T _max = null;
40
41 public void setMinimum(ValueExpression minimum)
42 {
43 _minimum = minimum;
44 }
45
46 public void setMaximum(ValueExpression maximum)
47 {
48 _maximum = maximum;
49 }
50
51 @Override
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 @Override
67 protected Validator createValidator() throws JspException
68 {
69 if (null == _minimum && null == _maximum)
70 {
71 throw new JspException("a minimum and / or a maximum have to be specified");
72 }
73 ELContext elContext = FacesContext.getCurrentInstance().getELContext();
74 if (null != _minimum)
75 {
76 _min = getValue(_minimum.getValue(elContext));
77 }
78 if (null != _maximum)
79 {
80 _max = getValue(_maximum.getValue(elContext));
81 }
82 if (null != _minimum && null != _maximum)
83 {
84 if (!isMinLTMax())
85 {
86 throw new JspException("maximum limit must be greater than the minimum limit");
87 }
88 }
89 return super.createValidator();
90 }
91
92
93
94
95 protected abstract boolean isMinLTMax();
96
97
98
99
100
101
102
103 protected abstract T getValue(Object value);
104 }