1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package javax.faces.webapp; |
20 | |
|
21 | |
import javax.faces.component.EditableValueHolder; |
22 | |
import javax.faces.component.UIComponent; |
23 | |
import javax.faces.validator.Validator; |
24 | |
import javax.servlet.jsp.JspException; |
25 | |
import javax.servlet.jsp.tagext.Tag; |
26 | |
import javax.servlet.jsp.tagext.TagSupport; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | 0 | public abstract class ValidatorELTag |
33 | |
extends TagSupport |
34 | |
{ |
35 | |
private static final long serialVersionUID = 8794036166323016663L; |
36 | |
|
37 | |
public int doStartTag() |
38 | |
throws javax.servlet.jsp.JspException |
39 | |
{ |
40 | 0 | UIComponentClassicTagBase componentTag = UIComponentELTag.getParentUIComponentClassicTagBase(pageContext); |
41 | 0 | if (componentTag == null) |
42 | |
{ |
43 | 0 | throw new JspException("no parent UIComponentTag found"); |
44 | |
} |
45 | 0 | if (!componentTag.getCreated()) |
46 | |
{ |
47 | 0 | return Tag.SKIP_BODY; |
48 | |
} |
49 | |
|
50 | 0 | Validator validator = createValidator(); |
51 | |
|
52 | 0 | UIComponent component = componentTag.getComponentInstance(); |
53 | 0 | if (component == null) |
54 | |
{ |
55 | 0 | throw new JspException("parent UIComponentTag has no UIComponent"); |
56 | |
} |
57 | 0 | if (!(component instanceof EditableValueHolder)) |
58 | |
{ |
59 | 0 | throw new JspException("UIComponent is no EditableValueHolder"); |
60 | |
} |
61 | 0 | ((EditableValueHolder)component).addValidator(validator); |
62 | |
|
63 | 0 | return Tag.SKIP_BODY; |
64 | |
} |
65 | |
|
66 | |
protected abstract Validator createValidator() |
67 | |
throws JspException; |
68 | |
|
69 | |
} |