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