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.renderkit.html.scarborough.standard.tag;
21  
22  import org.apache.myfaces.tobago.component.UIHidden;
23  import org.apache.myfaces.tobago.layout.Display;
24  import org.apache.myfaces.tobago.renderkit.InputRendererBase;
25  import org.apache.myfaces.tobago.renderkit.css.Style;
26  import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
27  import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
28  import org.apache.myfaces.tobago.renderkit.html.HtmlInputTypes;
29  import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtils;
30  import org.apache.myfaces.tobago.renderkit.util.RenderUtils;
31  import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
32  
33  import javax.faces.component.UIComponent;
34  import javax.faces.context.FacesContext;
35  import java.io.IOException;
36  
37  // TODO: Its not nice, that the base class use layout
38  public class HiddenRenderer extends InputRendererBase {
39  
40    public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
41  
42      final String clientId = component.getClientId(facesContext);
43      final String value = RenderUtils.currentValue(component);
44  
45      TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
46  
47      writer.startElement(HtmlElements.INPUT, component);
48      if (component instanceof UIHidden && ((UIHidden) component).isDisabled()) {
49        writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.TEXT, false);
50        Style style = new Style();
51        style.setDisplay(Display.NONE);
52        writer.writeStyleAttribute(style);
53        writer.writeAttribute(HtmlAttributes.DISABLED, true);
54      } else {
55        writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.HIDDEN, false);
56      }
57      writer.writeNameAttribute(clientId);
58      writer.writeIdAttribute(clientId);
59      HtmlRendererUtils.writeDataAttributes(facesContext, writer, component);
60      writer.writeAttribute(HtmlAttributes.VALUE, value != null ? value : "", true);
61      writer.endElement(HtmlElements.INPUT);
62    }
63  }