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 text renderer
042: */
043: class HtmlInputSecretRenderer extends Renderer {
044: public static final Renderer RENDERER = new HtmlInputSecretRenderer();
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: String alt;
082: String autocomplete;
083: String dir;
084: boolean disabled;
085: String lang;
086: int maxlength;
087:
088: String onblur;
089: String onchange;
090: String onclick;
091: String ondblclick;
092: String onfocus;
093:
094: String onkeydown;
095: String onkeypress;
096: String onkeyup;
097:
098: String onmousedown;
099: String onmousemove;
100: String onmouseout;
101: String onmouseover;
102: String onmouseup;
103:
104: String onselect;
105:
106: boolean readonly;
107: boolean redisplay;
108: int size;
109: String style;
110: String styleClass;
111: String tabindex;
112: String title;
113:
114: Object value;
115:
116: if (component instanceof HtmlInputSecret) {
117: HtmlInputSecret htmlInput = (HtmlInputSecret) component;
118:
119: accesskey = htmlInput.getAccesskey();
120: autocomplete = htmlInput.getAutocomplete();
121: alt = htmlInput.getAlt();
122: dir = htmlInput.getDir();
123: disabled = htmlInput.isDisabled();
124: lang = htmlInput.getLang();
125: maxlength = htmlInput.getMaxlength();
126: onblur = htmlInput.getOnblur();
127: onchange = htmlInput.getOnchange();
128: onclick = htmlInput.getOnclick();
129: ondblclick = htmlInput.getOndblclick();
130: onfocus = htmlInput.getOnfocus();
131:
132: onkeydown = htmlInput.getOnkeydown();
133: onkeypress = htmlInput.getOnkeypress();
134: onkeyup = htmlInput.getOnkeyup();
135:
136: onmousedown = htmlInput.getOnmousedown();
137: onmousemove = htmlInput.getOnmousemove();
138: onmouseout = htmlInput.getOnmouseout();
139: onmouseover = htmlInput.getOnmouseover();
140: onmouseup = htmlInput.getOnmouseup();
141:
142: onselect = htmlInput.getOnselect();
143:
144: readonly = htmlInput.isReadonly();
145: redisplay = htmlInput.isRedisplay();
146: size = htmlInput.getSize();
147: style = htmlInput.getStyle();
148: styleClass = htmlInput.getStyleClass();
149: tabindex = htmlInput.getTabindex();
150: title = htmlInput.getTitle();
151:
152: value = htmlInput.getValue();
153: } else {
154: Map<String, Object> attrMap = component.getAttributes();
155:
156: accesskey = (String) attrMap.get("accesskey");
157: alt = (String) attrMap.get("alt");
158: autocomplete = (String) attrMap.get("autocomplete");
159: dir = (String) attrMap.get("dir");
160: disabled = (Boolean) attrMap.get("disabled");
161: lang = (String) attrMap.get("lang");
162: maxlength = (Integer) attrMap.get("maxlength");
163:
164: onblur = (String) attrMap.get("onblur");
165: onchange = (String) attrMap.get("onchange");
166: onclick = (String) attrMap.get("onclick");
167: ondblclick = (String) attrMap.get("ondblclick");
168: onfocus = (String) attrMap.get("onfocus");
169:
170: onkeydown = (String) attrMap.get("onkeydown");
171: onkeypress = (String) attrMap.get("onkeypress");
172: onkeyup = (String) attrMap.get("onkeyup");
173:
174: onmousedown = (String) attrMap.get("onmousedown");
175: onmousemove = (String) attrMap.get("onmousemove");
176: onmouseout = (String) attrMap.get("onmouseout");
177: onmouseover = (String) attrMap.get("onmouseover");
178: onmouseup = (String) attrMap.get("onmouseup");
179:
180: onselect = (String) attrMap.get("onselect");
181:
182: readonly = (Boolean) attrMap.get("readonly");
183: redisplay = (Boolean) attrMap.get("redisplay");
184: size = (Integer) attrMap.get("size");
185: style = (String) attrMap.get("style");
186: styleClass = (String) attrMap.get("styleClass");
187: tabindex = (String) attrMap.get("tabindex");
188: title = (String) attrMap.get("title");
189:
190: value = attrMap.get("value");
191: }
192:
193: out.startElement("input", component);
194:
195: out.writeAttribute("type", "password", "type");
196:
197: out.writeAttribute("name", component.getClientId(context),
198: "name");
199:
200: if (id != null && !id.startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
201: out.writeAttribute("id", component.getClientId(context),
202: "id");
203:
204: if (accesskey != null)
205: out.writeAttribute("accesskey", accesskey, "accesskey");
206:
207: if (alt != null)
208: out.writeAttribute("alt", alt, "alt");
209:
210: if ("off".equals(autocomplete))
211: out.writeAttribute("autocomplete", "off", "autocomplete");
212:
213: if (dir != null)
214: out.writeAttribute("dir", dir, "dir");
215:
216: if (disabled)
217: out.writeAttribute("disabled", "disabled", "disabled");
218:
219: if (lang != null)
220: out.writeAttribute("lang", lang, "lang");
221:
222: if (maxlength > 0)
223: out.writeAttribute("maxlength", String.valueOf(maxlength),
224: "maxlength");
225:
226: if (onblur != null)
227: out.writeAttribute("onblur", onblur, "onblur");
228:
229: if (onchange != null)
230: out.writeAttribute("onchange", onchange, "onchange");
231:
232: if (onclick != null)
233: out.writeAttribute("onclick", onclick, "onclick");
234:
235: if (ondblclick != null)
236: out.writeAttribute("ondblclick", ondblclick, "ondblclick");
237:
238: if (onfocus != null)
239: out.writeAttribute("onfocus", onfocus, "onfocus");
240:
241: if (onkeydown != null)
242: out.writeAttribute("onkeydown", onkeydown, "onkeydown");
243:
244: if (onkeypress != null)
245: out.writeAttribute("onkeypress", onkeypress, "onkeypress");
246:
247: if (onkeyup != null)
248: out.writeAttribute("onkeyup", onkeyup, "onkeyup");
249:
250: if (onmousedown != null)
251: out.writeAttribute("onmousedown", onmousedown,
252: "onmousedown");
253:
254: if (onmousemove != null)
255: out.writeAttribute("onmousemove", onmousemove,
256: "onmousemove");
257:
258: if (onmouseout != null)
259: out.writeAttribute("onmouseout", onmouseout, "onmouseout");
260:
261: if (onmouseover != null)
262: out.writeAttribute("onmouseover", onmouseover,
263: "onmouseover");
264:
265: if (onmouseup != null)
266: out.writeAttribute("onmouseup", onmouseup, "onmouseup");
267:
268: if (onselect != null)
269: out.writeAttribute("onselect", onselect, "onselect");
270:
271: if (readonly)
272: out.writeAttribute("readonly", "readonly", "readonly");
273:
274: if (redisplay)
275: out.writeAttribute("redisplay", "redisplay", "redisplay");
276:
277: if (size > 0)
278: out.writeAttribute("size", String.valueOf(size), "size");
279:
280: if (style != null)
281: out.writeAttribute("style", style, "style");
282:
283: if (styleClass != null)
284: out.writeAttribute("class", styleClass, "class");
285:
286: if (tabindex != null)
287: out.writeAttribute("tabindex", tabindex, "tabindex");
288:
289: if (title != null)
290: out.writeAttribute("title", title, "title");
291:
292: if (redisplay && value != null)
293: out.writeAttribute("value", String.valueOf(value), "value");
294: }
295:
296: /**
297: * Renders the content for the component.
298: */
299: @Override
300: public void encodeChildren(FacesContext context,
301: UIComponent component) throws IOException {
302: /*
303: ResponseWriter out = context.getResponseWriter();
304:
305: if (component instanceof HtmlInputText) {
306: HtmlInputText htmlInput = (HtmlInputText) component;
307:
308: Object value = htmlInput.getValue();
309:
310: if (value == null)
311: return;
312:
313: out.writeText(value, "value");
314: }
315: else {
316: Map<String,Object> attrMap = component.getAttributes();
317:
318: Object value = attrMap.get("value");
319:
320: if (value == null)
321: return;
322:
323: out.writeText(value, "value");
324: }
325: */
326: }
327:
328: /**
329: * Renders the closing tag for the component.
330: */
331: @Override
332: public void encodeEnd(FacesContext context, UIComponent component)
333: throws IOException {
334: ResponseWriter out = context.getResponseWriter();
335:
336: out.endElement("input");
337: }
338:
339: public String toString() {
340: return "HtmlInputTextRenderer[]";
341: }
342: }
|