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