1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package javax.faces.component;
20
21 import javax.el.ValueExpression;
22 import javax.faces.context.FacesContext;
23
24 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
25 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
26
27
28
29
30
31
32
33
34 @JSFComponent(defaultRendererType = "javax.faces.Image")
35 public class UIGraphic extends UIComponentBase
36 {
37 public static final String COMPONENT_TYPE = "javax.faces.Graphic";
38 public static final String COMPONENT_FAMILY = "javax.faces.Graphic";
39
40 private static final String URL_PROPERTY = "url";
41 private static final String VALUE_PROPERTY = "value";
42
43 private Object _value;
44
45
46
47
48 public UIGraphic()
49 {
50 setRendererType("javax.faces.Image");
51 }
52
53 @Override
54 public String getFamily()
55 {
56 return COMPONENT_FAMILY;
57 }
58
59
60
61
62 @JSFProperty
63 public String getUrl()
64 {
65 return (String) getValue();
66 }
67
68 public void setUrl(String url)
69 {
70 setValue(url);
71 }
72
73 @Override
74 public ValueExpression getValueExpression(String name)
75 {
76 if (URL_PROPERTY.equals(name))
77 {
78 return super.getValueExpression(VALUE_PROPERTY);
79 }
80 else
81 {
82 return super.getValueExpression(name);
83 }
84 }
85
86 @Override
87 public void setValueExpression(String name, ValueExpression binding)
88 {
89 if (URL_PROPERTY.equals(name))
90 {
91 super.setValueExpression(VALUE_PROPERTY, binding);
92 }
93 else
94 {
95 super.setValueExpression(name, binding);
96 }
97 }
98
99
100
101
102
103
104
105 @JSFProperty
106 public Object getValue()
107 {
108 if (_value != null)
109 {
110 return _value;
111 }
112 ValueExpression expression = getValueExpression("value");
113 if (expression != null)
114 {
115 return expression.getValue(getFacesContext().getELContext());
116 }
117 return null;
118 }
119
120 public void setValue(Object value)
121 {
122 this._value = value;
123 }
124
125 @Override
126 public Object saveState(FacesContext facesContext)
127 {
128 Object[] values = new Object[2];
129 values[0] = super.saveState(facesContext);
130 values[1] = _value;
131
132 return values;
133 }
134
135 @Override
136 public void restoreState(FacesContext facesContext, Object state)
137 {
138 Object[] values = (Object[]) state;
139 super.restoreState(facesContext, values[0]);
140 _value = values[1];
141 }
142 }