1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.struts.faces.taglib;
18
19
20 import javax.faces.component.UIComponent;
21 import javax.faces.el.ValueBinding;
22 import javax.faces.webapp.UIComponentTag;
23
24
25 /***
26 * <p>Abstract base class for custom component tags for the
27 * <em>Struts-Faces Integration Library</em>.</p>
28 *
29 *
30 * @version $Rev: 421138 $ $Date: 2006-07-11 22:41:40 -0700 (Tue, 11 Jul 2006) $
31 */
32
33 public abstract class AbstractFacesTag extends UIComponentTag {
34
35
36
37
38
39 /***
40 * <p>The servlet context attribute under which our
41 * <code>MessageResources</code> bundle is stored.</p>
42 */
43 protected String bundle = null;
44
45 public void setBundle(String bundle) {
46 this.bundle = bundle;
47 }
48
49
50 /***
51 * <p>The CSS style(s) used to render this component.</p>
52 */
53 protected String style = null;
54
55 public void setStyle(String style) {
56 this.style = style;
57 }
58
59
60 /***
61 * <p>The CSS style class(es) used to render this component.</p>
62 */
63 protected String styleClass = null;
64
65 public void setStyleClass(String styleClass) {
66 this.styleClass = styleClass;
67 }
68
69
70 /***
71 * <p>The literal value to be rendered.</p>
72 */
73 protected String value = null;
74
75 public void setValue(String value) {
76 this.value = value;
77 }
78
79
80
81
82
83 /***
84 * <p>Return the component type of the component to be created for
85 * this tag.</p>
86 */
87 public abstract String getComponentType();
88
89
90 /***
91 * <p>Return the <code>rendererType</code> to be used for rendering
92 * our component.</p>
93 */
94 public abstract String getRendererType();
95
96
97 /***
98 * <p>Release any variables allocated during use of this tag instance.</p>
99 */
100 public void release() {
101
102 super.release();
103 this.bundle = null;
104 this.style = null;
105 this.styleClass = null;
106 this.value = null;
107
108 }
109
110
111
112
113
114 /***
115 * <p>Override attributes set on this tag instance.</p>
116 *
117 * @param component Component whose attributes should be overridden
118 */
119 protected void setProperties(UIComponent component) {
120
121 super.setProperties(component);
122 setStringAttribute(component, "bundle", bundle);
123 setStringAttribute(component, "style", style);
124 setStringAttribute(component, "styleClass", styleClass);
125 setStringAttribute(component, "value", value);
126
127 }
128
129
130
131
132
133 /***
134 * <p>If the specified attribute value is not <code>null</code>
135 * use it to either store a value binding expression for the
136 * specified attribute name, or store it as the literal value
137 * of the attribute.</p>
138 *
139 * @param component <code>UIComponent</code> whose attribute
140 * is to be set
141 * @param name Attribute name
142 * @param value Attribute value (or <code>null</code>)
143 *
144 * @exception NumberFormatException if the value does not
145 * contain a parsable integer
146 * @exception ReferenceSyntaxException if the expression has
147 * invalid syntax
148 */
149 protected void setBooleanAttribute(UIComponent component,
150 String name, String value) {
151
152 if (value == null) {
153 return;
154 }
155 if (isValueReference(value)) {
156 ValueBinding vb =
157 getFacesContext().getApplication().createValueBinding(value);
158 component.setValueBinding(name, vb);
159 } else {
160 component.getAttributes().put(name, Boolean.valueOf(value));
161 }
162
163 }
164
165
166 /***
167 * <p>If the specified attribute value is not <code>null</code>
168 * use it to either store a value binding expression for the
169 * specified attribute name, or store it as the literal value
170 * of the attribute.</p>
171 *
172 * @param component <code>UIComponent</code> whose attribute
173 * is to be set
174 * @param name Attribute name
175 * @param value Attribute value (or <code>null</code>)
176 *
177 * @exception NumberFormatException if the value does not
178 * contain a parsable integer
179 * @exception ReferenceSyntaxException if the expression has
180 * invalid syntax
181 */
182 protected void setIntegerAttribute(UIComponent component,
183 String name, String value) {
184
185 if (value == null) {
186 return;
187 }
188 if (isValueReference(value)) {
189 ValueBinding vb =
190 getFacesContext().getApplication().createValueBinding(value);
191 component.setValueBinding(name, vb);
192 } else {
193 component.getAttributes().put(name, Integer.valueOf(value));
194 }
195
196 }
197
198
199 /***
200 * <p>If the specified attribute value is not <code>null</code>
201 * use it to either store a value binding expression for the
202 * specified attribute name, or store it as the literal value
203 * of the attribute.</p>
204 *
205 * @param component <code>UIComponent</code> whose attribute
206 * is to be set
207 * @param name Attribute name
208 * @param value Attribute value (or <code>null</code>)
209 *
210 * @exception ReferenceSyntaxException if the expression has
211 * invalid syntax
212 */
213 protected void setStringAttribute(UIComponent component,
214 String name, String value) {
215
216 if (value == null) {
217 return;
218 }
219 if (isValueReference(value)) {
220 ValueBinding vb =
221 getFacesContext().getApplication().createValueBinding(value);
222 component.setValueBinding(name, vb);
223 } else {
224 component.getAttributes().put(name, value);
225 }
226
227 }
228 }