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