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: import java.util.logging.*;
034:
035: import javax.faces.*;
036: import javax.faces.component.*;
037: import javax.faces.component.html.*;
038: import javax.faces.context.*;
039: import javax.faces.render.*;
040:
041: /**
042: * The HTML text renderer
043: */
044: class HtmlInputTextRenderer extends BaseRenderer {
045: private static final Logger log = Logger
046: .getLogger(HtmlInputTextRenderer.class.getName());
047:
048: public static final Renderer RENDERER = new HtmlInputTextRenderer();
049:
050: /**
051: * True if the renderer is responsible for rendering the children.
052: */
053: @Override
054: public boolean getRendersChildren() {
055: return true;
056: }
057:
058: /**
059: * Decodes the data from the form.
060: */
061: @Override
062: public void decode(FacesContext context, UIComponent component) {
063: String clientId = component.getClientId(context);
064:
065: ExternalContext ext = context.getExternalContext();
066: Map<String, String> paramMap = ext.getRequestParameterMap();
067:
068: String value = paramMap.get(clientId);
069:
070: if (value != null) {
071: ((EditableValueHolder) component).setSubmittedValue(value);
072:
073: if (log.isLoggable(Level.FINER)) {
074: log.finer("JSF[" + context.getViewRoot().getViewId()
075: + "] h:inputText[" + clientId + "] =" + value);
076: }
077: }
078: }
079:
080: /**
081: * Renders the open tag for the text.
082: */
083: @Override
084: public void encodeBegin(FacesContext context, UIComponent component)
085: throws IOException {
086: ResponseWriter out = context.getResponseWriter();
087:
088: String id = component.getId();
089:
090: String accesskey;
091: String alt;
092: String autocomplete;
093: String dir;
094: boolean disabled;
095: String lang;
096: int maxlength;
097:
098: String onblur;
099: String onchange;
100: String onclick;
101: String ondblclick;
102: String onfocus;
103:
104: String onkeydown;
105: String onkeypress;
106: String onkeyup;
107:
108: String onmousedown;
109: String onmousemove;
110: String onmouseout;
111: String onmouseover;
112: String onmouseup;
113:
114: String onselect;
115:
116: boolean readonly;
117: int size;
118: String style;
119: String styleClass;
120: String tabindex;
121: String title;
122:
123: Object value;
124:
125: if (component instanceof HtmlInputText) {
126: HtmlInputText htmlInput = (HtmlInputText) component;
127:
128: accesskey = htmlInput.getAccesskey();
129: autocomplete = htmlInput.getAutocomplete();
130: alt = htmlInput.getAlt();
131: dir = htmlInput.getDir();
132: disabled = htmlInput.isDisabled();
133: lang = htmlInput.getLang();
134: maxlength = htmlInput.getMaxlength();
135:
136: onblur = htmlInput.getOnblur();
137: onchange = htmlInput.getOnchange();
138: onclick = htmlInput.getOnclick();
139: ondblclick = htmlInput.getOndblclick();
140: onfocus = htmlInput.getOnfocus();
141:
142: onkeydown = htmlInput.getOnkeydown();
143: onkeypress = htmlInput.getOnkeypress();
144: onkeyup = htmlInput.getOnkeyup();
145:
146: onmousedown = htmlInput.getOnmousedown();
147: onmousemove = htmlInput.getOnmousemove();
148: onmouseout = htmlInput.getOnmouseout();
149: onmouseover = htmlInput.getOnmouseover();
150: onmouseup = htmlInput.getOnmouseup();
151:
152: onselect = htmlInput.getOnselect();
153:
154: readonly = htmlInput.isReadonly();
155: size = htmlInput.getSize();
156: style = htmlInput.getStyle();
157: styleClass = htmlInput.getStyleClass();
158: tabindex = htmlInput.getTabindex();
159: title = htmlInput.getTitle();
160:
161: value = htmlInput.getValue();
162: } else {
163: Map<String, Object> attrMap = component.getAttributes();
164:
165: accesskey = (String) attrMap.get("accesskey");
166: alt = (String) attrMap.get("alt");
167: autocomplete = (String) attrMap.get("autocomplete");
168: dir = (String) attrMap.get("dir");
169: disabled = (Boolean) attrMap.get("disabled");
170: lang = (String) attrMap.get("lang");
171: maxlength = (Integer) attrMap.get("maxlength");
172:
173: onblur = (String) attrMap.get("onblur");
174: onchange = (String) attrMap.get("onchange");
175: onclick = (String) attrMap.get("onclick");
176: ondblclick = (String) attrMap.get("ondblclick");
177: onfocus = (String) attrMap.get("onfocus");
178:
179: onkeydown = (String) attrMap.get("onkeydown");
180: onkeypress = (String) attrMap.get("onkeypress");
181: onkeyup = (String) attrMap.get("onkeyup");
182:
183: onmousedown = (String) attrMap.get("onmousedown");
184: onmousemove = (String) attrMap.get("onmousemove");
185: onmouseout = (String) attrMap.get("onmouseout");
186: onmouseover = (String) attrMap.get("onmouseover");
187: onmouseup = (String) attrMap.get("onmouseup");
188:
189: onselect = (String) attrMap.get("onselect");
190:
191: readonly = (Boolean) attrMap.get("readonly");
192: size = (Integer) attrMap.get("size");
193: style = (String) attrMap.get("style");
194: styleClass = (String) attrMap.get("styleClass");
195: tabindex = (String) attrMap.get("tabindex");
196: title = (String) attrMap.get("title");
197:
198: value = attrMap.get("value");
199: }
200:
201: out.startElement("input", component);
202:
203: out.writeAttribute("name", component.getClientId(context),
204: "name");
205:
206: out.writeAttribute("type", "text", "type");
207:
208: if (id != null && !id.startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
209: out.writeAttribute("id", component.getClientId(context),
210: "id");
211:
212: if (accesskey != null)
213: out.writeAttribute("accesskey", accesskey, "accesskey");
214:
215: if (alt != null)
216: out.writeAttribute("alt", alt, "alt");
217:
218: if ("off".equals(autocomplete))
219: out.writeAttribute("autocomplete", "off", "autocomplete");
220:
221: if (dir != null)
222: out.writeAttribute("dir", dir, "dir");
223:
224: if (disabled)
225: out.writeAttribute("disabled", "disabled", "disabled");
226:
227: if (lang != null)
228: out.writeAttribute("lang", lang, "lang");
229:
230: if (maxlength > 0)
231: out.writeAttribute("maxlength", String.valueOf(maxlength),
232: "maxlength");
233:
234: if (onblur != null)
235: out.writeAttribute("onblur", onblur, "onblur");
236:
237: if (onchange != null)
238: out.writeAttribute("onchange", onchange, "onchange");
239:
240: if (onclick != null)
241: out.writeAttribute("onclick", onclick, "onclick");
242:
243: if (ondblclick != null)
244: out.writeAttribute("ondblclick", ondblclick, "ondblclick");
245:
246: if (onfocus != null)
247: out.writeAttribute("onfocus", onfocus, "onfocus");
248:
249: if (onkeydown != null)
250: out.writeAttribute("onkeydown", onkeydown, "onkeydown");
251:
252: if (onkeypress != null)
253: out.writeAttribute("onkeypress", onkeypress, "onkeypress");
254:
255: if (onkeyup != null)
256: out.writeAttribute("onkeyup", onkeyup, "onkeyup");
257:
258: if (onmousedown != null)
259: out.writeAttribute("onmousedown", onmousedown,
260: "onmousedown");
261:
262: if (onmousemove != null)
263: out.writeAttribute("onmousemove", onmousemove,
264: "onmousemove");
265:
266: if (onmouseout != null)
267: out.writeAttribute("onmouseout", onmouseout, "onmouseout");
268:
269: if (onmouseover != null)
270: out.writeAttribute("onmouseover", onmouseover,
271: "onmouseover");
272:
273: if (onmouseup != null)
274: out.writeAttribute("onmouseup", onmouseup, "onmouseup");
275:
276: if (onselect != null)
277: out.writeAttribute("onselect", onselect, "onselect");
278:
279: if (readonly)
280: out.writeAttribute("readonly", "readonly", "readonly");
281:
282: if (size > 0)
283: out.writeAttribute("size", String.valueOf(size), "size");
284:
285: if (style != null)
286: out.writeAttribute("style", style, "style");
287:
288: if (styleClass != null)
289: out.writeAttribute("class", styleClass, "class");
290:
291: if (tabindex != null)
292: out.writeAttribute("tabindex", tabindex, "tabindex");
293:
294: if (title != null)
295: out.writeAttribute("title", title, "title");
296:
297: out.writeAttribute("value",
298: toString(context, component, value), "value");
299: }
300:
301: /**
302: * Renders the content for the component.
303: */
304: @Override
305: public void encodeChildren(FacesContext context,
306: UIComponent component) throws IOException {
307: /*
308: ResponseWriter out = context.getResponseWriter();
309:
310: if (component instanceof HtmlInputText) {
311: HtmlInputText htmlInput = (HtmlInputText) component;
312:
313: Object value = htmlInput.getValue();
314:
315: if (value == null)
316: return;
317:
318: out.writeText(value, "value");
319: }
320: else {
321: Map<String,Object> attrMap = component.getAttributes();
322:
323: Object value = attrMap.get("value");
324:
325: if (value == null)
326: return;
327:
328: out.writeText(value, "value");
329: }
330: */
331: }
332:
333: /**
334: * Renders the closing tag for the component.
335: */
336: @Override
337: public void encodeEnd(FacesContext context, UIComponent component)
338: throws IOException {
339: ResponseWriter out = context.getResponseWriter();
340:
341: out.endElement("input");
342: }
343:
344: public String toString() {
345: return "HtmlInputTextRenderer[]";
346: }
347: }
|