001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License version 2
011: * as published by the Free Software Foundation.
012: *
013: * Resin Open Source is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
016: * of NON-INFRINGEMENT. See the GNU General Public License for more
017: * details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with Resin Open Source; if not, write to the
021: *
022: * Free Software Foundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.jsf.html;
030:
031: import java.io.*;
032: import java.util.*;
033:
034: import javax.faces.*;
035: import javax.faces.application.*;
036: import javax.faces.component.*;
037: import javax.faces.component.html.*;
038: import javax.faces.convert.*;
039: import javax.faces.context.*;
040: import javax.faces.render.*;
041:
042: /**
043: * The HTML selectMany/listbox renderer
044: */
045: class HtmlSelectManyListboxRenderer extends SelectRenderer {
046: public static final Renderer RENDERER = new HtmlSelectManyListboxRenderer();
047:
048: /**
049: * True if the renderer is responsible for rendering the children.
050: */
051: @Override
052: public boolean getRendersChildren() {
053: return true;
054: }
055:
056: /**
057: * Decodes the data from the form.
058: */
059: @Override
060: public void decode(FacesContext context, UIComponent component) {
061: String clientId = component.getClientId(context);
062:
063: ExternalContext ext = context.getExternalContext();
064: Map<String, String[]> paramMap = ext
065: .getRequestParameterValuesMap();
066:
067: String[] value = paramMap.get(clientId);
068:
069: if (value != null) {
070: ((EditableValueHolder) component).setSubmittedValue(value);
071: }
072: }
073:
074: /**
075: * Renders the open tag for the text.
076: */
077: @Override
078: public void encodeBegin(FacesContext context, UIComponent component)
079: throws IOException {
080: ResponseWriter out = context.getResponseWriter();
081:
082: String id = component.getId();
083:
084: String accesskey;
085: String dir;
086: boolean disabled;
087: String disabledClass;
088: String enabledClass;
089: String lang;
090:
091: String onblur;
092: String onchange;
093: String onclick;
094: String ondblclick;
095: String onfocus;
096:
097: String onkeydown;
098: String onkeypress;
099: String onkeyup;
100:
101: String onmousedown;
102: String onmousemove;
103: String onmouseout;
104: String onmouseover;
105: String onmouseup;
106:
107: String onselect;
108:
109: boolean readonly;
110: int size;
111: String style;
112: String styleClass;
113: String tabindex;
114: String title;
115: Object[] values;
116:
117: if (component instanceof HtmlSelectManyListbox) {
118: HtmlSelectManyListbox htmlComponent = (HtmlSelectManyListbox) component;
119:
120: accesskey = htmlComponent.getAccesskey();
121: dir = htmlComponent.getDir();
122: disabled = htmlComponent.isDisabled();
123: disabledClass = htmlComponent.getDisabledClass();
124: enabledClass = htmlComponent.getEnabledClass();
125: lang = htmlComponent.getLang();
126:
127: onblur = htmlComponent.getOnblur();
128: onchange = htmlComponent.getOnchange();
129: onclick = htmlComponent.getOnclick();
130: ondblclick = htmlComponent.getOndblclick();
131: onfocus = htmlComponent.getOnfocus();
132:
133: onkeydown = htmlComponent.getOnkeydown();
134: onkeypress = htmlComponent.getOnkeypress();
135: onkeyup = htmlComponent.getOnkeyup();
136:
137: onmousedown = htmlComponent.getOnmousedown();
138: onmousemove = htmlComponent.getOnmousemove();
139: onmouseout = htmlComponent.getOnmouseout();
140: onmouseover = htmlComponent.getOnmouseover();
141: onmouseup = htmlComponent.getOnmouseup();
142:
143: onselect = htmlComponent.getOnselect();
144:
145: readonly = htmlComponent.isReadonly();
146: size = htmlComponent.getSize();
147: style = htmlComponent.getStyle();
148: styleClass = htmlComponent.getStyleClass();
149: tabindex = htmlComponent.getTabindex();
150: title = htmlComponent.getTitle();
151:
152: values = htmlComponent.getSelectedValues();
153: } else {
154: Map<String, Object> attrMap = component.getAttributes();
155:
156: accesskey = (String) attrMap.get("accesskey");
157: dir = (String) attrMap.get("dir");
158: disabled = (Boolean) attrMap.get("disabled");
159: disabledClass = (String) attrMap.get("disabledClass");
160: enabledClass = (String) attrMap.get("enabledClass");
161: lang = (String) attrMap.get("lang");
162:
163: onblur = (String) attrMap.get("onblur");
164: onchange = (String) attrMap.get("onchange");
165: onclick = (String) attrMap.get("onclick");
166: ondblclick = (String) attrMap.get("ondblclick");
167: onfocus = (String) attrMap.get("onfocus");
168:
169: onkeydown = (String) attrMap.get("onkeydown");
170: onkeypress = (String) attrMap.get("onkeypress");
171: onkeyup = (String) attrMap.get("onkeyup");
172:
173: onmousedown = (String) attrMap.get("onmousedown");
174: onmousemove = (String) attrMap.get("onmousemove");
175: onmouseout = (String) attrMap.get("onmouseout");
176: onmouseover = (String) attrMap.get("onmouseover");
177: onmouseup = (String) attrMap.get("onmouseup");
178:
179: onselect = (String) attrMap.get("onselect");
180:
181: readonly = (Boolean) attrMap.get("readonly");
182: size = (Integer) attrMap.get("size");
183: style = (String) attrMap.get("style");
184: styleClass = (String) attrMap.get("styleClass");
185: tabindex = (String) attrMap.get("tabindex");
186: title = (String) attrMap.get("title");
187:
188: values = (Object[]) attrMap.get("selectedValues");
189: }
190:
191: UIViewRoot viewRoot = context.getViewRoot();
192:
193: out.startElement("select", component);
194:
195: if (style != null)
196: out.writeAttribute("style", style, "style");
197:
198: if (styleClass != null)
199: out.writeAttribute("class", styleClass, "class");
200:
201: String clientId = component.getClientId(context);
202: out.writeAttribute("name", clientId, "name");
203:
204: if (id != null && !id.startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
205: out.writeAttribute("id", clientId, "id");
206:
207: out.writeAttribute("multiple", "multiple", "multiple");
208:
209: if (size > 0)
210: out.writeAttribute("size", String.valueOf(size), "size");
211: else
212: out.writeAttribute("size", String.valueOf(component
213: .getChildCount()), "size");
214:
215: if (disabled)
216: out.writeAttribute("disabled", "disabled", "disabled");
217:
218: if (accesskey != null)
219: out.writeAttribute("accesskey", accesskey, "accesskey");
220:
221: if (dir != null)
222: out.writeAttribute("dir", dir, "dir");
223:
224: if (lang != null)
225: out.writeAttribute("lang", lang, "lang");
226:
227: if (onblur != null)
228: out.writeAttribute("onblur", onblur, "onblur");
229:
230: if (onchange != null)
231: out.writeAttribute("onchange", onchange, "onchange");
232:
233: if (onclick != null)
234: out.writeAttribute("onclick", onclick, "onclick");
235:
236: if (ondblclick != null)
237: out.writeAttribute("ondblclick", ondblclick, "ondblclick");
238:
239: if (onfocus != null)
240: out.writeAttribute("onfocus", onfocus, "onfocus");
241:
242: if (onkeydown != null)
243: out.writeAttribute("onkeydown", onkeydown, "onkeydown");
244:
245: if (onkeypress != null)
246: out.writeAttribute("onkeypress", onkeypress, "onkeypress");
247:
248: if (onkeyup != null)
249: out.writeAttribute("onkeyup", onkeyup, "onkeyup");
250:
251: if (onmousedown != null)
252: out.writeAttribute("onmousedown", onmousedown,
253: "onmousedown");
254:
255: if (onmousemove != null)
256: out.writeAttribute("onmousemove", onmousemove,
257: "onmousemove");
258:
259: if (onmouseout != null)
260: out.writeAttribute("onmouseout", onmouseout, "onmouseout");
261:
262: if (onmouseover != null)
263: out.writeAttribute("onmouseover", onmouseover,
264: "onmouseover");
265:
266: if (onmouseup != null)
267: out.writeAttribute("onmouseup", onmouseup, "onmouseup");
268:
269: if (onselect != null)
270: out.writeAttribute("onselect", onselect, "onselect");
271:
272: if (readonly)
273: out.writeAttribute("readonly", "readonly", "readonly");
274:
275: if (tabindex != null)
276: out.writeAttribute("tabindex", tabindex, "tabindex");
277:
278: if (title != null)
279: out.writeAttribute("title", title, "title");
280: out.write("\n");
281:
282: encodeChildren(out, context, component, values, enabledClass,
283: disabledClass);
284:
285: out.endElement("select");
286: out.write("\n");
287: }
288:
289: /**
290: * Renders the content for the component.
291: */
292: @Override
293: public void encodeChildren(FacesContext context,
294: UIComponent component) throws IOException {
295: }
296:
297: /**
298: * Renders the closing tag for the component.
299: */
300: @Override
301: public void encodeEnd(FacesContext context, UIComponent component)
302: throws IOException {
303: }
304:
305: public String toString() {
306: return "HtmlInputTextRenderer[]";
307: }
308: }
|