View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.renderkit.html;
20  
21  import java.io.IOException;
22  
23  import javax.faces.component.UIComponent;
24  import javax.faces.component.UIInput;
25  import javax.faces.component.UIOutput;
26  import javax.faces.context.FacesContext;
27  import javax.faces.context.ResponseWriter;
28  import javax.faces.convert.ConverterException;
29  
30  import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFRenderer;
31  import org.apache.myfaces.shared_impl.renderkit.JSFAttr;
32  import org.apache.myfaces.shared_impl.renderkit.RendererUtils;
33  import org.apache.myfaces.shared_impl.renderkit.html.HTML;
34  import org.apache.myfaces.shared_impl.renderkit.html.HtmlRenderer;
35  import org.apache.myfaces.shared_impl.renderkit.html.HtmlRendererUtils;
36  
37  
38  /**
39   *   
40   * @author Thomas Spiegl (latest modification by $Author: lu4242 $)
41   * @author Anton Koinov
42   * @version $Revision: 693358 $ $Date: 2008-09-08 22:54:29 -0500 (Mon, 08 Sep 2008) $
43   */
44  @JSFRenderer(
45      renderKitId="HTML_BASIC",
46      family="javax.faces.Input",
47      type="javax.faces.Hidden")
48  public class HtmlHiddenRenderer
49  extends HtmlRenderer
50  {
51      public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
52          throws IOException
53      {
54          RendererUtils.checkParamValidity(facesContext, uiComponent, UIInput.class);
55  
56          ResponseWriter writer = facesContext.getResponseWriter();
57  
58          writer.startElement(HTML.INPUT_ELEM, uiComponent);
59          writer.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_HIDDEN, null);
60  
61          String clientId = uiComponent.getClientId(facesContext);
62          writer.writeAttribute(HTML.ID_ATTR, clientId, null);
63          writer.writeAttribute(HTML.NAME_ATTR, clientId, null);
64  
65          String value = RendererUtils.getStringValue(facesContext, uiComponent);
66          if (value != null)
67          {
68              writer.writeAttribute(HTML.VALUE_ATTR, value, JSFAttr.VALUE_ATTR);
69          }
70  
71          writer.endElement(HTML.INPUT_ELEM);
72      }
73  
74      public Object getConvertedValue(FacesContext facesContext, UIComponent uiComponent, Object submittedValue) throws ConverterException
75      {
76          RendererUtils.checkParamValidity(facesContext, uiComponent, UIOutput.class);
77          return RendererUtils.getConvertedUIOutputValue(facesContext,
78                                                         (UIOutput)uiComponent,
79                                                         submittedValue);
80      }
81  
82  
83      public void decode(FacesContext facesContext, UIComponent component)
84       {
85           RendererUtils.checkParamValidity(facesContext,component,null);
86  
87           if (component instanceof UIInput)
88           {
89               HtmlRendererUtils.decodeUIInput(facesContext, component);
90           }
91           else
92           {
93               throw new IllegalArgumentException("Unsupported component class " + component.getClass().getName());
94           }
95       }
96  
97  }