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  
20  package org.apache.myfaces.tobago.internal.renderkit.renderer;
21  
22  import org.apache.myfaces.tobago.internal.component.AbstractUIHidden;
23  import org.apache.myfaces.tobago.internal.util.HtmlRendererUtils;
24  import org.apache.myfaces.tobago.internal.util.RenderUtils;
25  import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
26  import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
27  import org.apache.myfaces.tobago.renderkit.html.HtmlInputTypes;
28  import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
29  
30  import javax.faces.context.FacesContext;
31  import java.io.IOException;
32  
33  public class HiddenRenderer<T extends AbstractUIHidden> extends DecodingInputRendererBase<T> {
34  
35    @Override
36    protected boolean isOutputOnly(T component) {
37      return component.isDisabled();
38    }
39  
40    @Override
41    public void encodeBeginInternal(final FacesContext facesContext, final T component) throws IOException {
42  
43      final String clientId = component.getClientId(facesContext);
44      final String value = RenderUtils.currentValue(component);
45  
46      final TobagoResponseWriter writer = getResponseWriter(facesContext);
47  
48      writer.startElement(HtmlElements.INPUT);
49      if (component.isDisabled()) {
50        // XXX why text instead of hidden here?
51        writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.TEXT);
52        writer.writeAttribute(HtmlAttributes.DISABLED, true);
53      } else {
54        writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.HIDDEN);
55      }
56      writer.writeNameAttribute(clientId);
57      writer.writeIdAttribute(clientId);
58      HtmlRendererUtils.writeDataAttributes(facesContext, writer, component);
59      writer.writeAttribute(HtmlAttributes.VALUE, value != null ? value : "", true);
60    }
61  
62    @Override
63    public void encodeEndInternal(final FacesContext facesContext, final T component) throws IOException {
64      final TobagoResponseWriter writer = getResponseWriter(facesContext);
65      writer.endElement(HtmlElements.INPUT);
66    }
67  }