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
55
56
57
58
59
60 @JSFJspTag(name="f:validator",bodyContent="empty")
61 public class ValidatorImplTag
62 extends ValidatorELTag
63 {
64 private ValueExpression _validatorId;
65 private ValueExpression _binding;
66 private String _validatorIdString = null;
67
68
69
70
71 @JSFJspAttribute(
72 rtexprvalue=true,
73 className="java.lang.String")
74 public void setValidatorId(ValueExpression validatorId)
75 {
76 _validatorId = validatorId;
77 }
78
79
80
81
82
83 @JSFJspAttribute(
84 rtexprvalue=true,
85 className="javax.faces.validator.Validator")
86 public void setBinding(ValueExpression binding)
87 {
88 _binding = binding;
89 }
90
91
92
93
94
95
96 public void setValidatorIdString(String validatorIdString)
97 {
98 _validatorIdString = validatorIdString;
99 }
100
101 public void release()
102 {
103 super.release();
104 _validatorId = null;
105 _binding = null;
106 _validatorIdString = null;
107 }
108
109 protected Validator createValidator() throws javax.servlet.jsp.JspException
110 {
111
112 if (_validatorIdString != null)
113 {
114 return this.createClassicValidator();
115 }
116 if (_validatorId != null && _validatorId.isLiteralText())
117 {
118 return this.createClassicValidator();
119 }
120
121 return new DelegateValidator(_validatorId, _binding,
122 _validatorIdString);
123 }
124
125 protected Validator createClassicValidator() throws javax.servlet.jsp.JspException
126 {
127 FacesContext facesContext = FacesContext.getCurrentInstance();
128 ELContext elContext = facesContext.getELContext();
129 if (null != _binding)
130 {
131 Object validator;
132 try
133 {
134 validator = _binding.getValue(elContext);
135 } catch (Exception e)
136 {
137 throw new JspException("Error while creating the Validator", e);
138 }
139 if (validator instanceof Validator)
140 {
141 return (Validator) validator;
142 }
143 }
144 Application application = facesContext.getApplication();
145 Validator validator = null;
146 try
147 {
148
149 if (null != _validatorIdString)
150 {
151 validator = application.createValidator(_validatorIdString);
152 } else if (null != _validatorId)
153 {
154 String validatorId = (String) _validatorId.getValue(elContext);
155 validator = application.createValidator(validatorId);
156 }
157 } catch (Exception e)
158 {
159 throw new JspException("Error while creating the Validator", e);
160 }
161
162 if (null != validator)
163 {
164 if (null != _binding)
165 {
166 _binding.setValue(elContext, validator);
167 }
168 return validator;
169 }
170 throw new JspException("validatorId and/or binding must be specified");
171 }
172
173 }