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 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | 0 | public class ValidatorTag extends ValidatorELTag |
37 | |
{ |
38 | |
private ValueExpression _validatorId; |
39 | |
private ValueExpression _binding; |
40 | 0 | private String _validatorIdString = null; |
41 | |
|
42 | |
public void setValidatorId(ValueExpression validatorId) |
43 | |
{ |
44 | 0 | _validatorId = validatorId; |
45 | 0 | } |
46 | |
|
47 | |
public void setBinding(ValueExpression binding) |
48 | |
{ |
49 | 0 | _binding = binding; |
50 | 0 | } |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
public void setValidatorIdString(String validatorIdString) |
58 | |
{ |
59 | 0 | _validatorIdString = validatorIdString; |
60 | 0 | } |
61 | |
|
62 | |
@Override |
63 | |
public void release() |
64 | |
{ |
65 | 0 | super.release(); |
66 | 0 | _validatorId = null; |
67 | 0 | _binding = null; |
68 | 0 | _validatorIdString = null; |
69 | 0 | } |
70 | |
|
71 | |
@Override |
72 | |
protected Validator createValidator() throws javax.servlet.jsp.JspException |
73 | |
{ |
74 | 0 | FacesContext facesContext = FacesContext.getCurrentInstance(); |
75 | 0 | ELContext elContext = facesContext.getELContext(); |
76 | 0 | if (null != _binding) |
77 | |
{ |
78 | |
Object validator; |
79 | |
try |
80 | |
{ |
81 | 0 | validator = _binding.getValue(elContext); |
82 | |
} |
83 | 0 | catch (Exception e) |
84 | |
{ |
85 | 0 | throw new JspException("Error while creating the Validator", e); |
86 | 0 | } |
87 | 0 | if (validator instanceof Validator) |
88 | |
{ |
89 | 0 | return (Validator)validator; |
90 | |
} |
91 | |
} |
92 | 0 | Application application = facesContext.getApplication(); |
93 | 0 | Validator validator = null; |
94 | |
try |
95 | |
{ |
96 | |
|
97 | 0 | if (null != _validatorIdString) |
98 | |
{ |
99 | 0 | validator = application.createValidator(_validatorIdString); |
100 | |
} |
101 | 0 | else if (null != _validatorId) |
102 | |
{ |
103 | 0 | String validatorId = (String)_validatorId.getValue(elContext); |
104 | 0 | validator = application.createValidator(validatorId); |
105 | |
} |
106 | |
} |
107 | 0 | catch (Exception e) |
108 | |
{ |
109 | 0 | throw new JspException("Error while creating the Validator", e); |
110 | 0 | } |
111 | |
|
112 | 0 | if (null != validator) |
113 | |
{ |
114 | 0 | if (null != _binding) |
115 | |
{ |
116 | 0 | _binding.setValue(elContext, validator); |
117 | |
} |
118 | 0 | return validator; |
119 | |
} |
120 | 0 | throw new JspException("validatorId and/or binding must be specified"); |
121 | |
} |
122 | |
|
123 | |
} |