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 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 UIComponentClassicTagBase componentTag = UIComponentELTag.getParentUIComponentClassicTagBase(pageContext);
41 if (componentTag == null)
42 {
43 throw new JspException("no parent UIComponentTag found");
44 }
45 if (!componentTag.getCreated())
46 {
47 return Tag.SKIP_BODY;
48 }
49
50 Validator validator = createValidator();
51
52 UIComponent component = componentTag.getComponentInstance();
53 if (component == null)
54 {
55 throw new JspException("parent UIComponentTag has no UIComponent");
56 }
57 if (!(component instanceof EditableValueHolder))
58 {
59 throw new JspException("UIComponent is no EditableValueHolder");
60 }
61 ((EditableValueHolder)component).addValidator(validator);
62
63 return Tag.SKIP_BODY;
64 }
65
66 protected abstract Validator createValidator()
67 throws JspException;
68
69 }