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.application.Application; |
24 | |
import javax.faces.context.FacesContext; |
25 | |
import javax.faces.validator.Validator; |
26 | |
import javax.faces.webapp.ValidatorELTag; |
27 | |
import javax.servlet.jsp.JspException; |
28 | |
|
29 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspAttribute; |
30 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspTag; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
@JSFJspTag(name = "f:validator", bodyContent = "empty") |
55 | 0 | public class ValidatorImplTag extends ValidatorELTag |
56 | |
{ |
57 | |
private ValueExpression _validatorId; |
58 | |
private ValueExpression _binding; |
59 | 0 | private String _validatorIdString = null; |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
@JSFJspAttribute(className="javax.el.ValueExpression", |
65 | |
deferredValueType="java.lang.String") |
66 | |
public void setValidatorId(ValueExpression validatorId) |
67 | |
{ |
68 | 0 | _validatorId = validatorId; |
69 | 0 | } |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
@JSFJspAttribute(className="javax.el.ValueExpression", |
75 | |
deferredValueType="javax.faces.validator.Validator") |
76 | |
public void setBinding(ValueExpression binding) |
77 | |
{ |
78 | 0 | _binding = binding; |
79 | 0 | } |
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
public void setValidatorIdString(String validatorIdString) |
87 | |
{ |
88 | 0 | _validatorIdString = validatorIdString; |
89 | 0 | } |
90 | |
|
91 | |
@Override |
92 | |
public void release() |
93 | |
{ |
94 | 0 | super.release(); |
95 | 0 | _validatorId = null; |
96 | 0 | _binding = null; |
97 | 0 | _validatorIdString = null; |
98 | 0 | } |
99 | |
|
100 | |
@Override |
101 | |
protected Validator createValidator() throws javax.servlet.jsp.JspException |
102 | |
{ |
103 | |
|
104 | 0 | if (_validatorIdString != null) |
105 | |
{ |
106 | 0 | return this.createClassicValidator(); |
107 | |
} |
108 | 0 | if (_validatorId != null && _validatorId.isLiteralText()) |
109 | |
{ |
110 | 0 | return this.createClassicValidator(); |
111 | |
} |
112 | |
|
113 | 0 | return new DelegateValidator(_validatorId, _binding, _validatorIdString); |
114 | |
} |
115 | |
|
116 | |
protected Validator createClassicValidator() throws javax.servlet.jsp.JspException |
117 | |
{ |
118 | 0 | FacesContext facesContext = FacesContext.getCurrentInstance(); |
119 | 0 | ELContext elContext = facesContext.getELContext(); |
120 | 0 | if (null != _binding) |
121 | |
{ |
122 | |
Object validator; |
123 | |
try |
124 | |
{ |
125 | 0 | validator = _binding.getValue(elContext); |
126 | |
} |
127 | 0 | catch (Exception e) |
128 | |
{ |
129 | 0 | throw new JspException("Error while creating the Validator", e); |
130 | 0 | } |
131 | 0 | if (validator instanceof Validator) |
132 | |
{ |
133 | 0 | return (Validator)validator; |
134 | |
} |
135 | |
} |
136 | 0 | Application application = facesContext.getApplication(); |
137 | 0 | Validator validator = null; |
138 | |
try |
139 | |
{ |
140 | |
|
141 | 0 | if (null != _validatorIdString) |
142 | |
{ |
143 | 0 | validator = application.createValidator(_validatorIdString); |
144 | |
} |
145 | 0 | else if (null != _validatorId) |
146 | |
{ |
147 | 0 | String validatorId = (String)_validatorId.getValue(elContext); |
148 | 0 | validator = application.createValidator(validatorId); |
149 | |
} |
150 | |
} |
151 | 0 | catch (Exception e) |
152 | |
{ |
153 | 0 | throw new JspException("Error while creating the Validator", e); |
154 | 0 | } |
155 | |
|
156 | 0 | if (null != validator) |
157 | |
{ |
158 | 0 | if (null != _binding) |
159 | |
{ |
160 | 0 | _binding.setValue(elContext, validator); |
161 | |
} |
162 | 0 | return validator; |
163 | |
} |
164 | 0 | throw new JspException("validatorId and/or binding must be specified"); |
165 | |
} |
166 | |
|
167 | |
} |