01: /*
02: * Copyright 2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.apache.myfaces.renderkit.html;
17:
18: import org.apache.myfaces.shared_impl.renderkit.JSFAttr;
19: import org.apache.myfaces.shared_impl.renderkit.RendererUtils;
20: import org.apache.myfaces.shared_impl.renderkit.html.HTML;
21: import org.apache.myfaces.shared_impl.renderkit.html.HtmlRenderer;
22: import org.apache.myfaces.shared_impl.renderkit.html.HtmlRendererUtils;
23:
24: import javax.faces.component.UIComponent;
25: import javax.faces.component.UIInput;
26: import javax.faces.component.UIOutput;
27: import javax.faces.context.FacesContext;
28: import javax.faces.context.ResponseWriter;
29: import javax.faces.convert.ConverterException;
30: import java.io.IOException;
31:
32: /**
33: * @author Thomas Spiegl (latest modification by $Author: schof $)
34: * @author Anton Koinov
35: * @version $Revision: 382015 $ $Date: 2006-03-01 14:47:11 +0100 (Mi, 01 Mrz 2006) $
36: */
37: public class HtmlHiddenRenderer extends HtmlRenderer {
38: public void encodeEnd(FacesContext facesContext,
39: UIComponent uiComponent) throws IOException {
40: RendererUtils.checkParamValidity(facesContext, uiComponent,
41: UIInput.class);
42:
43: ResponseWriter writer = facesContext.getResponseWriter();
44:
45: writer.startElement(HTML.INPUT_ELEM, uiComponent);
46: writer.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_HIDDEN,
47: null);
48:
49: String clientId = uiComponent.getClientId(facesContext);
50: writer.writeAttribute(HTML.ID_ATTR, clientId, null);
51: writer.writeAttribute(HTML.NAME_ATTR, clientId, null);
52:
53: String value = RendererUtils.getStringValue(facesContext,
54: uiComponent);
55: if (value != null) {
56: writer.writeAttribute(HTML.VALUE_ATTR, value,
57: JSFAttr.VALUE_ATTR);
58: }
59:
60: writer.endElement(HTML.INPUT_ELEM);
61: }
62:
63: public Object getConvertedValue(FacesContext facesContext,
64: UIComponent uiComponent, Object submittedValue)
65: throws ConverterException {
66: RendererUtils.checkParamValidity(facesContext, uiComponent,
67: UIOutput.class);
68: return RendererUtils.getConvertedUIOutputValue(facesContext,
69: (UIOutput) uiComponent, submittedValue);
70: }
71:
72: public void decode(FacesContext facesContext, UIComponent component) {
73: RendererUtils.checkParamValidity(facesContext, component, null);
74:
75: if (component instanceof UIInput) {
76: HtmlRendererUtils.decodeUIInput(facesContext, component);
77: } else {
78: throw new IllegalArgumentException(
79: "Unsupported component class "
80: + component.getClass().getName());
81: }
82: }
83:
84: }
|