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.model.*;
041: import javax.faces.render.*;
042:
043: /**
044: * The HTML selectMany/checkbox renderer
045: */
046: class HtmlSelectOneMenuRenderer extends SelectRenderer {
047: public static final Renderer RENDERER = new HtmlSelectOneMenuRenderer();
048:
049: /**
050: * True if the renderer is responsible for rendering the children.
051: */
052: @Override
053: public boolean getRendersChildren() {
054: return true;
055: }
056:
057: /**
058: * Decodes the data from the form.
059: */
060: @Override
061: public void decode(FacesContext context, UIComponent component) {
062: String clientId = component.getClientId(context);
063:
064: ExternalContext ext = context.getExternalContext();
065: Map<String, String> paramMap = ext.getRequestParameterMap();
066:
067: String value = paramMap.get(clientId);
068:
069: if (value != null)
070: ((EditableValueHolder) component).setSubmittedValue(value);
071: }
072:
073: /**
074: * Renders the open tag for the text.
075: */
076: @Override
077: public void encodeBegin(FacesContext context, UIComponent component)
078: throws IOException {
079: ResponseWriter out = context.getResponseWriter();
080:
081: String id = component.getId();
082:
083: String accesskey;
084: String dir;
085: boolean disabled;
086: String disabledClass;
087: String enabledClass;
088: String lang;
089:
090: String onblur;
091: String onchange;
092: String onclick;
093: String ondblclick;
094: String onfocus;
095:
096: String onkeydown;
097: String onkeypress;
098: String onkeyup;
099:
100: String onmousedown;
101: String onmousemove;
102: String onmouseout;
103: String onmouseover;
104: String onmouseup;
105:
106: String onselect;
107:
108: boolean readonly;
109: String style;
110: String styleClass;
111: String tabindex;
112: String title;
113: Object value;
114:
115: if (component instanceof HtmlSelectOneMenu) {
116: HtmlSelectOneMenu htmlComponent = (HtmlSelectOneMenu) 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: style = htmlComponent.getStyle();
145: styleClass = htmlComponent.getStyleClass();
146: tabindex = htmlComponent.getTabindex();
147: title = htmlComponent.getTitle();
148:
149: value = htmlComponent.getValue();
150: } else {
151: Map<String, Object> attrMap = component.getAttributes();
152:
153: accesskey = (String) attrMap.get("accesskey");
154: dir = (String) attrMap.get("dir");
155: disabled = Boolean.TRUE.equals(attrMap.get("disabled"));
156: disabledClass = (String) attrMap.get("disabledClass");
157: enabledClass = (String) attrMap.get("enabledClass");
158: lang = (String) attrMap.get("lang");
159:
160: onblur = (String) attrMap.get("onblur");
161: onchange = (String) attrMap.get("onchange");
162: onclick = (String) attrMap.get("onclick");
163: ondblclick = (String) attrMap.get("ondblclick");
164: onfocus = (String) attrMap.get("onfocus");
165:
166: onkeydown = (String) attrMap.get("onkeydown");
167: onkeypress = (String) attrMap.get("onkeypress");
168: onkeyup = (String) attrMap.get("onkeyup");
169:
170: onmousedown = (String) attrMap.get("onmousedown");
171: onmousemove = (String) attrMap.get("onmousemove");
172: onmouseout = (String) attrMap.get("onmouseout");
173: onmouseover = (String) attrMap.get("onmouseover");
174: onmouseup = (String) attrMap.get("onmouseup");
175:
176: onselect = (String) attrMap.get("onselect");
177:
178: readonly = Boolean.TRUE.equals(attrMap.get("readonly"));
179: style = (String) attrMap.get("style");
180: styleClass = (String) attrMap.get("styleClass");
181: tabindex = (String) attrMap.get("tabindex");
182: title = (String) attrMap.get("title");
183:
184: value = attrMap.get("value");
185: }
186:
187: UIViewRoot viewRoot = context.getViewRoot();
188:
189: out.startElement("select", component);
190:
191: if (style != null)
192: out.writeAttribute("style", style, "style");
193:
194: if (styleClass != null)
195: out.writeAttribute("class", styleClass, "class");
196:
197: String clientId = component.getClientId(context);
198: out.writeAttribute("name", clientId, "name");
199:
200: if (id != null && !id.startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
201: out.writeAttribute("id", clientId, "id");
202:
203: if (disabled)
204: out.writeAttribute("disabled", "disabled", "disabled");
205:
206: if (accesskey != null)
207: out.writeAttribute("accesskey", accesskey, "accesskey");
208:
209: if (dir != null)
210: out.writeAttribute("dir", dir, "dir");
211:
212: if (lang != null)
213: out.writeAttribute("lang", lang, "lang");
214:
215: if (onblur != null)
216: out.writeAttribute("onblur", onblur, "onblur");
217:
218: if (onchange != null)
219: out.writeAttribute("onchange", onchange, "onchange");
220:
221: if (onclick != null)
222: out.writeAttribute("onclick", onclick, "onclick");
223:
224: if (ondblclick != null)
225: out.writeAttribute("ondblclick", ondblclick, "ondblclick");
226:
227: if (onfocus != null)
228: out.writeAttribute("onfocus", onfocus, "onfocus");
229:
230: if (onkeydown != null)
231: out.writeAttribute("onkeydown", onkeydown, "onkeydown");
232:
233: if (onkeypress != null)
234: out.writeAttribute("onkeypress", onkeypress, "onkeypress");
235:
236: if (onkeyup != null)
237: out.writeAttribute("onkeyup", onkeyup, "onkeyup");
238:
239: if (onmousedown != null)
240: out.writeAttribute("onmousedown", onmousedown,
241: "onmousedown");
242:
243: if (onmousemove != null)
244: out.writeAttribute("onmousemove", onmousemove,
245: "onmousemove");
246:
247: if (onmouseout != null)
248: out.writeAttribute("onmouseout", onmouseout, "onmouseout");
249:
250: if (onmouseover != null)
251: out.writeAttribute("onmouseover", onmouseover,
252: "onmouseover");
253:
254: if (onmouseup != null)
255: out.writeAttribute("onmouseup", onmouseup, "onmouseup");
256:
257: if (onselect != null)
258: out.writeAttribute("onselect", onselect, "onselect");
259:
260: if (readonly)
261: out.writeAttribute("readonly", "readonly", "readonly");
262:
263: if (tabindex != null)
264: out.writeAttribute("tabindex", tabindex, "tabindex");
265:
266: if (title != null)
267: out.writeAttribute("title", title, "title");
268:
269: out.writeAttribute("size", "1", "size");
270:
271: out.write("\n");
272:
273: encodeOneChildren(out, context, component, value, enabledClass,
274: disabledClass);
275:
276: out.endElement("select");
277: out.write("\n");
278: }
279:
280: /**
281: * Renders the content for the component.
282: */
283: @Override
284: public void encodeChildren(FacesContext context,
285: UIComponent component) throws IOException {
286: }
287:
288: /**
289: * Renders the closing tag for the component.
290: */
291: @Override
292: public void encodeEnd(FacesContext context, UIComponent component)
293: throws IOException {
294: }
295:
296: public String toString() {
297: return "HtmlInputTextRenderer[]";
298: }
299: }
|