1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.view.facelets.tag.jsf;
20
21 import java.io.IOException;
22
23 import javax.el.ELException;
24 import javax.el.ValueExpression;
25 import javax.faces.FacesException;
26 import javax.faces.component.EditableValueHolder;
27 import javax.faces.component.UIComponent;
28 import javax.faces.validator.Validator;
29 import javax.faces.view.facelets.FaceletContext;
30 import javax.faces.view.facelets.FaceletException;
31 import javax.faces.view.facelets.MetaRuleset;
32 import javax.faces.view.facelets.TagAttribute;
33 import javax.faces.view.facelets.TagConfig;
34 import javax.faces.view.facelets.TagException;
35 import javax.faces.view.facelets.ValidatorConfig;
36
37 import org.apache.myfaces.view.facelets.tag.MetaTagHandlerImpl;
38
39
40
41
42
43
44
45
46
47
48
49 @Deprecated
50 public class ValidateHandler extends MetaTagHandlerImpl
51 {
52
53 private final TagAttribute binding;
54
55 private String validatorId;
56
57
58
59
60
61
62 public ValidateHandler(TagConfig config)
63 {
64 super(config);
65 this.binding = this.getAttribute("binding");
66 }
67
68 public ValidateHandler(ValidatorConfig config)
69 {
70 this((TagConfig) config);
71 this.validatorId = config.getValidatorId();
72 }
73
74
75
76
77
78 public final void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException,
79 FaceletException, ELException
80 {
81
82 if (parent == null || !(parent instanceof EditableValueHolder))
83 {
84 throw new TagException(this.tag, "Parent not an instance of EditableValueHolder: " + parent);
85 }
86
87
88 if (parent.getParent() == null)
89 {
90
91 EditableValueHolder evh = (EditableValueHolder) parent;
92 ValueExpression ve = null;
93 Validator v = null;
94 if (this.binding != null)
95 {
96 ve = this.binding.getValueExpression(ctx, Validator.class);
97 v = (Validator) ve.getValue(ctx);
98 }
99 if (v == null)
100 {
101 v = this.createValidator(ctx);
102 if (ve != null)
103 {
104 ve.setValue(ctx, v);
105 }
106 }
107 if (v == null)
108 {
109 throw new TagException(this.tag, "No Validator was created");
110 }
111 this.setAttributes(ctx, v);
112 evh.addValidator(v);
113 }
114 }
115
116
117
118
119
120
121
122
123 protected Validator createValidator(FaceletContext ctx)
124 {
125 if (this.validatorId == null)
126 {
127 throw new TagException(
128 this.tag,
129 "Default behavior invoked of requiring a validator-id passed in the "
130 + "constructor, must override ValidateHandler(ValidatorConfig)");
131 }
132 return ctx.getFacesContext().getApplication().createValidator(this.validatorId);
133 }
134
135 protected MetaRuleset createMetaRuleset(Class type)
136 {
137 return super.createMetaRuleset(type).ignore("binding");
138 }
139
140 }