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 | 0 | super(config); |
65 | 0 | this.binding = this.getAttribute("binding"); |
66 | 0 | } |
67 | |
|
68 | |
public ValidateHandler(ValidatorConfig config) |
69 | |
{ |
70 | 0 | this((TagConfig) config); |
71 | 0 | this.validatorId = config.getValidatorId(); |
72 | 0 | } |
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
public final void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, |
79 | |
FaceletException, ELException |
80 | |
{ |
81 | |
|
82 | 0 | if (parent == null || !(parent instanceof EditableValueHolder)) |
83 | |
{ |
84 | 0 | throw new TagException(this.tag, "Parent not an instance of EditableValueHolder: " + parent); |
85 | |
} |
86 | |
|
87 | |
|
88 | 0 | if (parent.getParent() == null) |
89 | |
{ |
90 | |
|
91 | 0 | EditableValueHolder evh = (EditableValueHolder) parent; |
92 | 0 | ValueExpression ve = null; |
93 | 0 | Validator v = null; |
94 | 0 | if (this.binding != null) |
95 | |
{ |
96 | 0 | ve = this.binding.getValueExpression(ctx, Validator.class); |
97 | 0 | v = (Validator) ve.getValue(ctx); |
98 | |
} |
99 | 0 | if (v == null) |
100 | |
{ |
101 | 0 | v = this.createValidator(ctx); |
102 | 0 | if (ve != null) |
103 | |
{ |
104 | 0 | ve.setValue(ctx, v); |
105 | |
} |
106 | |
} |
107 | 0 | if (v == null) |
108 | |
{ |
109 | 0 | throw new TagException(this.tag, "No Validator was created"); |
110 | |
} |
111 | 0 | this.setAttributes(ctx, v); |
112 | 0 | evh.addValidator(v); |
113 | |
} |
114 | 0 | } |
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
protected Validator createValidator(FaceletContext ctx) |
124 | |
{ |
125 | 0 | if (this.validatorId == null) |
126 | |
{ |
127 | 0 | 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 | 0 | return ctx.getFacesContext().getApplication().createValidator(this.validatorId); |
133 | |
} |
134 | |
|
135 | |
protected MetaRuleset createMetaRuleset(Class type) |
136 | |
{ |
137 | 0 | return super.createMetaRuleset(type).ignore("binding"); |
138 | |
} |
139 | |
|
140 | |
} |