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 input/hidden renderer
042: */
043: class HtmlInputHiddenRenderer extends Renderer {
044: public static final Renderer RENDERER = new HtmlInputHiddenRenderer();
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: if (component instanceof HtmlInputHidden) {
081: HtmlInputHidden htmlInput = (HtmlInputHidden) component;
082: } else {
083: Map<String, Object> attrMap = component.getAttributes();
084: }
085:
086: out.startElement("input", component);
087: out.writeAttribute("type", "hidden", "type");
088:
089: out.writeAttribute("name", component.getClientId(context),
090: "name");
091:
092: if (id != null && !id.startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
093: out.writeAttribute("id", component.getClientId(context),
094: "id");
095:
096: if (component instanceof HtmlInputHidden) {
097: HtmlInputHidden htmlInput = (HtmlInputHidden) component;
098:
099: Object value = htmlInput.getValue();
100:
101: if (value == null)
102: return;
103:
104: out.writeAttribute("value", String.valueOf(value), "value");
105: } else {
106: Map<String, Object> attrMap = component.getAttributes();
107:
108: Object value = attrMap.get("value");
109:
110: if (value == null)
111: return;
112:
113: out.writeAttribute("value", String.valueOf(value), "value");
114: }
115: }
116:
117: /**
118: * Renders the content for the component.
119: */
120: @Override
121: public void encodeChildren(FacesContext context,
122: UIComponent component) throws IOException {
123: }
124:
125: /**
126: * Renders the closing tag for the component.
127: */
128: @Override
129: public void encodeEnd(FacesContext context, UIComponent component)
130: throws IOException {
131: ResponseWriter out = context.getResponseWriter();
132:
133: out.endElement("input");
134: }
135:
136: public String toString() {
137: return "HtmlInputHiddenRenderer[]";
138: }
139: }
|