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/checkbox renderer
044: */
045: class HtmlSelectOneListboxRenderer extends SelectRenderer {
046: public static final Renderer RENDERER = new HtmlSelectOneListboxRenderer();
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.getRequestParameterMap();
065:
066: String value = paramMap.get(clientId);
067:
068: if (value != null)
069: ((EditableValueHolder) component).setSubmittedValue(value);
070: }
071:
072: /**
073: * Renders the open tag for the text.
074: */
075: @Override
076: public void encodeBegin(FacesContext context, UIComponent component)
077: throws IOException {
078: ResponseWriter out = context.getResponseWriter();
079:
080: String id = component.getId();
081:
082: String accesskey;
083: String dir;
084: boolean disabled;
085: String disabledClass;
086: String enabledClass;
087: String lang;
088:
089: String onblur;
090: String onchange;
091: String onclick;
092: String ondblclick;
093: String onfocus;
094:
095: String onkeydown;
096: String onkeypress;
097: String onkeyup;
098:
099: String onmousedown;
100: String onmousemove;
101: String onmouseout;
102: String onmouseover;
103: String onmouseup;
104:
105: String onselect;
106:
107: boolean readonly;
108: int size = 0;
109: String style;
110: String styleClass;
111: String tabindex;
112: String title;
113: Object value;
114:
115: if (component instanceof HtmlSelectOneListbox) {
116: HtmlSelectOneListbox htmlComponent = (HtmlSelectOneListbox) component;
117:
118: accesskey = htmlComponent.getAccesskey();
119: dir = htmlComponent.getDir();
120: disabled = htmlComponent.isDisabled();
121: disabledClass = htmlComponent.getDisabledClass();
122: enabledClass = htmlComponent.getEnabledClass();
123: lang = htmlComponent.getLang();
124:
125: onblur = htmlComponent.getOnblur();
126: onchange = htmlComponent.getOnchange();
127: onclick = htmlComponent.getOnclick();
128: ondblclick = htmlComponent.getOndblclick();
129: onfocus = htmlComponent.getOnfocus();
130:
131: onkeydown = htmlComponent.getOnkeydown();
132: onkeypress = htmlComponent.getOnkeypress();
133: onkeyup = htmlComponent.getOnkeyup();
134:
135: onmousedown = htmlComponent.getOnmousedown();
136: onmousemove = htmlComponent.getOnmousemove();
137: onmouseout = htmlComponent.getOnmouseout();
138: onmouseover = htmlComponent.getOnmouseover();
139: onmouseup = htmlComponent.getOnmouseup();
140:
141: onselect = htmlComponent.getOnselect();
142:
143: readonly = htmlComponent.isReadonly();
144: size = htmlComponent.getSize();
145: style = htmlComponent.getStyle();
146: styleClass = htmlComponent.getStyleClass();
147: tabindex = htmlComponent.getTabindex();
148: title = htmlComponent.getTitle();
149:
150: value = htmlComponent.getValue();
151: } else {
152: Map<String, Object> attrMap = component.getAttributes();
153:
154: accesskey = (String) attrMap.get("accesskey");
155: dir = (String) attrMap.get("dir");
156: disabled = Boolean.TRUE.equals(attrMap.get("disabled"));
157: disabledClass = (String) attrMap.get("disabledClass");
158: enabledClass = (String) attrMap.get("enabledClass");
159: lang = (String) attrMap.get("lang");
160:
161: onblur = (String) attrMap.get("onblur");
162: onchange = (String) attrMap.get("onchange");
163: onclick = (String) attrMap.get("onclick");
164: ondblclick = (String) attrMap.get("ondblclick");
165: onfocus = (String) attrMap.get("onfocus");
166:
167: onkeydown = (String) attrMap.get("onkeydown");
168: onkeypress = (String) attrMap.get("onkeypress");
169: onkeyup = (String) attrMap.get("onkeyup");
170:
171: onmousedown = (String) attrMap.get("onmousedown");
172: onmousemove = (String) attrMap.get("onmousemove");
173: onmouseout = (String) attrMap.get("onmouseout");
174: onmouseover = (String) attrMap.get("onmouseover");
175: onmouseup = (String) attrMap.get("onmouseup");
176:
177: onselect = (String) attrMap.get("onselect");
178:
179: readonly = Boolean.TRUE.equals(attrMap.get("readonly"));
180: Integer iValue = (Integer) attrMap.get("size");
181: if (iValue != null)
182: size = iValue;
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: value = attrMap.get("value");
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: if (disabled)
208: out.writeAttribute("disabled", "disabled", "disabled");
209:
210: if (accesskey != null)
211: out.writeAttribute("accesskey", accesskey, "accesskey");
212:
213: if (dir != null)
214: out.writeAttribute("dir", dir, "dir");
215:
216: if (lang != null)
217: out.writeAttribute("lang", lang, "lang");
218:
219: if (onblur != null)
220: out.writeAttribute("onblur", onblur, "onblur");
221:
222: if (onchange != null)
223: out.writeAttribute("onchange", onchange, "onchange");
224:
225: if (onclick != null)
226: out.writeAttribute("onclick", onclick, "onclick");
227:
228: if (ondblclick != null)
229: out.writeAttribute("ondblclick", ondblclick, "ondblclick");
230:
231: if (onfocus != null)
232: out.writeAttribute("onfocus", onfocus, "onfocus");
233:
234: if (onkeydown != null)
235: out.writeAttribute("onkeydown", onkeydown, "onkeydown");
236:
237: if (onkeypress != null)
238: out.writeAttribute("onkeypress", onkeypress, "onkeypress");
239:
240: if (onkeyup != null)
241: out.writeAttribute("onkeyup", onkeyup, "onkeyup");
242:
243: if (onmousedown != null)
244: out.writeAttribute("onmousedown", onmousedown,
245: "onmousedown");
246:
247: if (onmousemove != null)
248: out.writeAttribute("onmousemove", onmousemove,
249: "onmousemove");
250:
251: if (onmouseout != null)
252: out.writeAttribute("onmouseout", onmouseout, "onmouseout");
253:
254: if (onmouseover != null)
255: out.writeAttribute("onmouseover", onmouseover,
256: "onmouseover");
257:
258: if (onmouseup != null)
259: out.writeAttribute("onmouseup", onmouseup, "onmouseup");
260:
261: if (onselect != null)
262: out.writeAttribute("onselect", onselect, "onselect");
263:
264: if (readonly)
265: out.writeAttribute("readonly", "readonly", "readonly");
266:
267: if (size > 0)
268: out.writeAttribute("size", String.valueOf(size), "size");
269: else {
270: int count = component.getChildCount();
271: out.writeAttribute("size", String.valueOf(count), "size");
272: }
273:
274: if (tabindex != null)
275: out.writeAttribute("tabindex", tabindex, "tabindex");
276:
277: if (title != null)
278: out.writeAttribute("title", title, "title");
279:
280: out.write("\n");
281:
282: encodeOneChildren(out, context, component, value, 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: }
|