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.UIComponent; |
22 | |
import javax.faces.context.FacesContext; |
23 | |
import javax.faces.el.ValueBinding; |
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 | |
|
33 | 0 | public class AttributeTag extends TagSupport |
34 | |
{ |
35 | |
private static final long serialVersionUID = 3147657100171678632L; |
36 | |
private String _name; |
37 | |
private String _value; |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
public void setName(String name) |
44 | |
{ |
45 | 0 | _name = name; |
46 | 0 | } |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
public void setValue(String value) |
53 | |
{ |
54 | 0 | _value = value; |
55 | 0 | } |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
@Override |
61 | |
public int doStartTag() throws JspException |
62 | |
{ |
63 | 0 | UIComponentTag componentTag = UIComponentTag.getParentUIComponentTag(pageContext); |
64 | 0 | if (componentTag == null) |
65 | |
{ |
66 | 0 | throw new JspException("no parent UIComponentTag found"); |
67 | |
} |
68 | 0 | UIComponent component = componentTag.getComponentInstance(); |
69 | 0 | if (component == null) |
70 | |
{ |
71 | 0 | throw new JspException("parent UIComponentTag has no UIComponent"); |
72 | |
} |
73 | 0 | String name = getName(); |
74 | 0 | if (component.getAttributes().get(name) == null) |
75 | |
{ |
76 | 0 | Object value = getValue(); |
77 | |
|
78 | 0 | if (value != null) |
79 | |
{ |
80 | 0 | component.getAttributes().put(name, value); |
81 | |
} |
82 | |
} |
83 | 0 | return Tag.SKIP_BODY; |
84 | |
} |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
@Override |
90 | |
public void release() |
91 | |
{ |
92 | 0 | super.release(); |
93 | 0 | _name = null; |
94 | 0 | _value = null; |
95 | 0 | } |
96 | |
|
97 | |
private String getName() |
98 | |
{ |
99 | 0 | if (UIComponentTag.isValueReference(_name)) |
100 | |
{ |
101 | 0 | FacesContext facesContext = FacesContext.getCurrentInstance(); |
102 | 0 | ValueBinding vb = facesContext.getApplication().createValueBinding(_name); |
103 | 0 | return (String)vb.getValue(facesContext); |
104 | |
} |
105 | |
|
106 | 0 | return _name; |
107 | |
} |
108 | |
|
109 | |
private Object getValue() |
110 | |
{ |
111 | 0 | if (UIComponentTag.isValueReference(_value)) |
112 | |
{ |
113 | 0 | FacesContext facesContext = FacesContext.getCurrentInstance(); |
114 | 0 | ValueBinding vb = facesContext.getApplication().createValueBinding(_value); |
115 | 0 | return vb.getValue(facesContext); |
116 | |
} |
117 | |
|
118 | 0 | return _value; |
119 | |
} |
120 | |
|
121 | |
} |