001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.faces.taglib.html;
018:
019: import org.apache.cocoon.faces.FacesUtils;
020: import org.apache.cocoon.faces.taglib.UIComponentTag;
021: import org.apache.commons.lang.BooleanUtils;
022:
023: import javax.faces.FacesException;
024: import javax.faces.component.UIComponent;
025: import javax.faces.component.UISelectOne;
026: import javax.faces.context.FacesContext;
027: import javax.faces.el.MethodBinding;
028: import javax.faces.event.ValueChangeEvent;
029:
030: /**
031: * @version CVS $Id: SelectOneListboxTag.java 433543 2006-08-22 06:22:54Z crossley $
032: */
033: public class SelectOneListboxTag extends UIComponentTag {
034:
035: private String converter;
036: private String immediate;
037: private String required;
038: private String validator;
039: private String value;
040: private String valueChangeListener;
041: private String accesskey;
042: private String dir;
043: private String disabled;
044: private String disabledClass;
045: private String enabledClass;
046: private String lang;
047: private String onblur;
048: private String onchange;
049: private String onclick;
050: private String ondblclick;
051: private String onfocus;
052: private String onkeydown;
053: private String onkeypress;
054: private String onkeyup;
055: private String onmousedown;
056: private String onmousemove;
057: private String onmouseout;
058: private String onmouseover;
059: private String onmouseup;
060: private String onselect;
061: private String readonly;
062: private String size;
063: private String style;
064: private String styleClass;
065: private String tabindex;
066: private String title;
067:
068: public void setConverter(String converter) {
069: this .converter = converter;
070: }
071:
072: public void setImmediate(String immediate) {
073: this .immediate = immediate;
074: }
075:
076: public void setRequired(String required) {
077: this .required = required;
078: }
079:
080: public void setValidator(String validator) {
081: this .validator = validator;
082: }
083:
084: public void setValue(String value) {
085: this .value = value;
086: }
087:
088: public void setValueChangeListener(String valueChangeListener) {
089: this .valueChangeListener = valueChangeListener;
090: }
091:
092: public void setAccesskey(String accesskey) {
093: this .accesskey = accesskey;
094: }
095:
096: public void setDir(String dir) {
097: this .dir = dir;
098: }
099:
100: public void setDisabled(String disabled) {
101: this .disabled = disabled;
102: }
103:
104: public void setDisabledClass(String disabledClass) {
105: this .disabledClass = disabledClass;
106: }
107:
108: public void setEnabledClass(String enabledClass) {
109: this .enabledClass = enabledClass;
110: }
111:
112: public void setLang(String lang) {
113: this .lang = lang;
114: }
115:
116: public void setOnblur(String onblur) {
117: this .onblur = onblur;
118: }
119:
120: public void setOnchange(String onchange) {
121: this .onchange = onchange;
122: }
123:
124: public void setOnclick(String onclick) {
125: this .onclick = onclick;
126: }
127:
128: public void setOndblclick(String ondblclick) {
129: this .ondblclick = ondblclick;
130: }
131:
132: public void setOnfocus(String onfocus) {
133: this .onfocus = onfocus;
134: }
135:
136: public void setOnkeydown(String onkeydown) {
137: this .onkeydown = onkeydown;
138: }
139:
140: public void setOnkeypress(String onkeypress) {
141: this .onkeypress = onkeypress;
142: }
143:
144: public void setOnkeyup(String onkeyup) {
145: this .onkeyup = onkeyup;
146: }
147:
148: public void setOnmousedown(String onmousedown) {
149: this .onmousedown = onmousedown;
150: }
151:
152: public void setOnmousemove(String onmousemove) {
153: this .onmousemove = onmousemove;
154: }
155:
156: public void setOnmouseout(String onmouseout) {
157: this .onmouseout = onmouseout;
158: }
159:
160: public void setOnmouseover(String onmouseover) {
161: this .onmouseover = onmouseover;
162: }
163:
164: public void setOnmouseup(String onmouseup) {
165: this .onmouseup = onmouseup;
166: }
167:
168: public void setOnselect(String onselect) {
169: this .onselect = onselect;
170: }
171:
172: public void setReadonly(String readonly) {
173: this .readonly = readonly;
174: }
175:
176: public void setSize(String size) {
177: this .size = size;
178: }
179:
180: public void setStyle(String style) {
181: this .style = style;
182: }
183:
184: public void setStyleClass(String styleClass) {
185: this .styleClass = styleClass;
186: }
187:
188: public void setTabindex(String tabindex) {
189: this .tabindex = tabindex;
190: }
191:
192: public void setTitle(String title) {
193: this .title = title;
194: }
195:
196: public String getRendererType() {
197: return "javax.faces.Listbox";
198: }
199:
200: public String getComponentType() {
201: return "javax.faces.HtmlSelectManyListbox";
202: }
203:
204: protected void setProperties(UIComponent component) {
205: super .setProperties(component);
206:
207: UISelectOne select;
208: try {
209: select = (UISelectOne) component;
210: } catch (ClassCastException cce) {
211: throw new FacesException("Tag <" + getClass().getName()
212: + "> expected UISelectOne. " + "Got <"
213: + component.getClass().getName() + ">");
214: }
215:
216: if (converter != null) {
217: if (FacesUtils.isExpression(converter)) {
218: select.setValueBinding("converter",
219: createValueBinding(converter));
220: } else {
221: select.setConverter(getApplication().createConverter(
222: converter));
223: }
224: }
225:
226: if (immediate != null) {
227: if (FacesUtils.isExpression(immediate)) {
228: select.setValueBinding("immediate",
229: createValueBinding(immediate));
230: } else {
231: select.setImmediate(BooleanUtils.toBoolean(immediate));
232: }
233: }
234:
235: if (required != null) {
236: if (FacesUtils.isExpression(required)) {
237: select.setValueBinding("required",
238: createValueBinding(required));
239: } else {
240: select.setRequired(BooleanUtils.toBoolean(required));
241: }
242: }
243:
244: if (validator != null) {
245: if (FacesUtils.isExpression(validator)) {
246: MethodBinding vb = getApplication()
247: .createMethodBinding(
248: validator,
249: new Class[] { FacesContext.class,
250: UIComponent.class, Object.class });
251: select.setValidator(vb);
252: } else {
253: throw new FacesException("Tag <" + getClass().getName()
254: + "> validator must be an expression. "
255: + "Got <" + validator + ">");
256: }
257: }
258:
259: if (value != null) {
260: if (FacesUtils.isExpression(value)) {
261: select.setValueBinding("value",
262: createValueBinding(value));
263: } else {
264: select.setValue(value);
265: }
266: }
267:
268: if (valueChangeListener != null) {
269: if (FacesUtils.isExpression(valueChangeListener)) {
270: MethodBinding vb = getApplication()
271: .createMethodBinding(valueChangeListener,
272: new Class[] { ValueChangeEvent.class });
273: select.setValueChangeListener(vb);
274: } else {
275: throw new FacesException(
276: "Tag <"
277: + getClass().getName()
278: + "> valueChangeListener must be an expression. "
279: + "Got <" + valueChangeListener + ">");
280: }
281: }
282:
283: setProperty(component, "accesskey", accesskey);
284:
285: setProperty(component, "dir", dir);
286:
287: setBooleanProperty(component, "disabled", disabled);
288:
289: setProperty(component, "disabledClass", disabledClass);
290: setProperty(component, "enabledClass", enabledClass);
291: setProperty(component, "lang", lang);
292: setProperty(component, "onblur", onblur);
293: setProperty(component, "onchange", onchange);
294: setProperty(component, "onclick", onclick);
295: setProperty(component, "ondblclick", ondblclick);
296: setProperty(component, "onfocus", onfocus);
297: setProperty(component, "onkeydown", onkeydown);
298: setProperty(component, "onkeypress", onkeypress);
299: setProperty(component, "onkeyup", onkeyup);
300: setProperty(component, "onmousedown", onmousedown);
301: setProperty(component, "onmousemove", onmousemove);
302: setProperty(component, "onmouseout", onmouseout);
303: setProperty(component, "onmouseover", onmouseover);
304: setProperty(component, "onmouseup", onmouseup);
305: setProperty(component, "onselect", onselect);
306:
307: setBooleanProperty(component, "readonly", readonly);
308: setIntegerProperty(component, "size", size);
309:
310: setProperty(component, "style", style);
311: setProperty(component, "styleClass", styleClass);
312: setProperty(component, "tabindex", tabindex);
313: setProperty(component, "title", title);
314: }
315:
316: public void recycle() {
317: super.recycle();
318: converter = null;
319: immediate = null;
320: required = null;
321: validator = null;
322: value = null;
323: valueChangeListener = null;
324: accesskey = null;
325: dir = null;
326: disabled = null;
327: disabledClass = null;
328: enabledClass = null;
329: lang = null;
330: onblur = null;
331: onchange = null;
332: onclick = null;
333: ondblclick = null;
334: onfocus = null;
335: onkeydown = null;
336: onkeypress = null;
337: onkeyup = null;
338: onmousedown = null;
339: onmousemove = null;
340: onmouseout = null;
341: onmouseover = null;
342: onmouseup = null;
343: onselect = null;
344: readonly = null;
345: size = null;
346: style = null;
347: styleClass = null;
348: tabindex = null;
349: title = null;
350: }
351: }
|