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.renderkit.JSFAttr;
32  import org.apache.myfaces.shared.renderkit.RendererUtils;
33  import org.apache.myfaces.shared.renderkit.html.HTML;
34  import org.apache.myfaces.shared.renderkit.html.HtmlRenderer;
35  import org.apache.myfaces.shared.renderkit.html.HtmlRendererUtils;
36  
37  /**
38   * 
39   * @author Thomas Spiegl (latest modification by $Author: bommel $)
40   * @author Anton Koinov
41   * @version $Revision: 1187700 $ $Date: 2011-10-22 07:19:37 -0500 (Sat, 22 Oct 2011) $
42   */
43  @JSFRenderer(renderKitId = "HTML_BASIC", family = "javax.faces.Input", type = "javax.faces.Hidden")
44  public class HtmlHiddenRenderer extends HtmlRenderer
45  {
46      @Override
47      public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) throws IOException
48      {
49          RendererUtils.checkParamValidity(facesContext, uiComponent, UIInput.class);
50  
51          ResponseWriter writer = facesContext.getResponseWriter();
52  
53          writer.startElement(HTML.INPUT_ELEM, uiComponent);
54          writer.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_HIDDEN, null);
55  
56          String clientId = uiComponent.getClientId(facesContext);
57          writer.writeAttribute(HTML.ID_ATTR, clientId, null);
58          writer.writeAttribute(HTML.NAME_ATTR, clientId, null);
59  
60          String value = RendererUtils.getStringValue(facesContext, uiComponent);
61          if (value != null)
62          {
63              writer.writeAttribute(HTML.VALUE_ATTR, value, JSFAttr.VALUE_ATTR);
64          }
65  
66          writer.endElement(HTML.INPUT_ELEM);
67      }
68  
69      @Override
70      public Object getConvertedValue(FacesContext facesContext, UIComponent uiComponent, Object submittedValue)
71          throws ConverterException
72      {
73          RendererUtils.checkParamValidity(facesContext, uiComponent, UIOutput.class);
74          return RendererUtils.getConvertedUIOutputValue(facesContext, (UIOutput)uiComponent, submittedValue);
75      }
76  
77      @Override
78      public void decode(FacesContext facesContext, UIComponent component)
79      {
80          RendererUtils.checkParamValidity(facesContext, component, null);
81  
82          if (component instanceof UIInput)
83          {
84              HtmlRendererUtils.decodeUIInput(facesContext, component);
85          }
86          else
87          {
88              throw new IllegalArgumentException("Unsupported component class " + component.getClass().getName());
89          }
90      }
91  
92  }