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.context.Markup;
23  import org.apache.myfaces.tobago.internal.component.AbstractUIButtons;
24  import org.apache.myfaces.tobago.internal.util.HtmlRendererUtils;
25  import org.apache.myfaces.tobago.layout.Orientation;
26  import org.apache.myfaces.tobago.renderkit.RendererBase;
27  import org.apache.myfaces.tobago.renderkit.css.BootstrapClass;
28  import org.apache.myfaces.tobago.renderkit.css.TobagoClass;
29  import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
30  import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
31  import org.apache.myfaces.tobago.renderkit.html.HtmlRoleValues;
32  import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
33  
34  import javax.faces.context.FacesContext;
35  import java.io.IOException;
36  
37  public class ButtonsRenderer<T extends AbstractUIButtons> extends RendererBase<T> {
38  
39    @Override
40    public void encodeBeginInternal(final FacesContext facesContext, final T component) throws IOException {
41  
42      final Markup markup = component.getMarkup();
43      final TobagoResponseWriter writer = getResponseWriter(facesContext);
44  
45      writer.startElement(HtmlElements.TOBAGO_BUTTONS);
46      writer.writeIdAttribute(component.getClientId(facesContext));
47  
48      writer.writeClassAttribute(
49          null,
50          TobagoClass.BUTTONS.createMarkup(markup),
51          Orientation.vertical.equals(component.getOrientation())
52              ? BootstrapClass.BTN_GROUP_VERTICAL : BootstrapClass.BTN_GROUP,
53          component.getCustomClass());
54      writer.writeAttribute(HtmlAttributes.ROLE, HtmlRoleValues.GROUP.toString(), false);
55      HtmlRendererUtils.writeDataAttributes(facesContext, writer, component);
56      final String tip = component.getTip();
57      if (tip != null) {
58        writer.writeAttribute(HtmlAttributes.TITLE, tip, true);
59      }
60  
61      insideBegin(facesContext, HtmlElements.TOBAGO_BUTTONS);
62    }
63  
64    @Override
65    public void encodeEndInternal(final FacesContext facesContext, final T component) throws IOException {
66      insideEnd(facesContext, HtmlElements.TOBAGO_BUTTONS);
67  
68      final TobagoResponseWriter writer = getResponseWriter(facesContext);
69      writer.endElement(HtmlElements.TOBAGO_BUTTONS);
70    }
71  }