/**
 *  Copyright 2014-16 by Riccardo Massera (TheCoder4.Eu) and Stephan Rauh (http://www.beyondjava.net).
 *  
 *  This file is part of BootsFaces.
 *  
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
 */

package net.bootsfaces.component.switchComponent;

import java.io.IOException;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.render.FacesRenderer;

import net.bootsfaces.component.selectBooleanCheckbox.SelectBooleanCheckbox;
import net.bootsfaces.component.selectBooleanCheckbox.SelectBooleanCheckboxRenderer;

/** This class generates the HTML code of &lt;b:switchWidget /&gt;. */
@FacesRenderer(componentFamily = "net.bootsfaces.component", rendererType = "net.bootsfaces.component.switch.Switch")
public class SwitchRenderer extends SelectBooleanCheckboxRenderer {

	@Override
	public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
		ResponseWriter rw = context.getResponseWriter();
		String clientId = component.getClientId();
		super.encodeBegin(context, component);
		clientId = clientId.replace(":", "\\\\:");
		rw.append("<script>");
		rw.append("$('#input_" + clientId + "').bootstrapSwitch();");
		rw.append("</script>");
	}

	/**
	 * The b:switch and the b:selectBooleanCheckbox share most of their code.
	 * This method allows to add extra attributes for the switch.
	 * 
	 * @param rw
	 * @param selectBooleanCheckbox
	 * @throws IOException
	 */
	protected void addAttributesForSwitch(ResponseWriter rw, SelectBooleanCheckbox selectBooleanCheckbox)
			throws IOException {
		Switch switchComponent = (Switch) selectBooleanCheckbox;
		writeAttribute(rw, "data-off-text", switchComponent.getOffText());
		writeAttribute(rw, "data-on-text", switchComponent.getOnText());
		writeAttribute(rw, "data-on-color", switchComponent.getOnColor());
		writeAttribute(rw, "data-off-color", switchComponent.getOffColor());
		if (switchComponent.isIndeterminate())
			writeAttribute(rw, "data-indeterminate", switchComponent.isIndeterminate());
		if (switchComponent.isInverse())
			writeAttribute(rw, "data-inverse", switchComponent.isInverse());
		writeAttribute(rw, "data-size", switchComponent.getSwitchsize());
		if (!switchComponent.isAnimate())
			writeAttribute(rw, "data-animate", switchComponent.isAnimate());
		if (switchComponent.isDisabled())
			writeAttribute(rw, "data-disabled", switchComponent.isDisabled());
		if (switchComponent.isReadonly())
			writeAttribute(rw, "data-readonly", switchComponent.isReadonly());
		writeAttribute(rw, "data-label-text", switchComponent.getLabelText());
		if (switchComponent.getHandleWidth() > 0)
			writeAttribute(rw, "data-handle-width", switchComponent.getHandleWidth());
		if (switchComponent.getLabelWidth() > 0)
			writeAttribute(rw, "data-label-width", switchComponent.getLabelWidth());
	}

}

@@ -1767,16 +1767,1335 @@
 %22);%0A%09%7D%0A%0A
+        /**%0A         * Renders the start of the input tag. This method is protected in order to%0A         * allow third-party frameworks to derive from it.%0A         *%0A         * @param rw%0A         *            the response writer%0A         * @param selectBooleanCheckbox%0A         *            the component to render%0A         * @throws IOException%0A         *             may be thrown by the response writer%0A         */%0A        @Override%0A        protected void renderInputTag(ResponseWriter rw, FacesContext context, SelectBooleanCheckbox selectBooleanCheckbox,%0A                                      String clientId) throws IOException %7B%0A%0A                rw.startElement(%22div%22, selectBooleanCheckbox);%0A                rw.writeAttribute(%22id%22, clientId, null);%0A                if (null != selectBooleanCheckbox.getDir()) %7B%0A                        rw.writeAttribute(%22dir%22, selectBooleanCheckbox.getDir(), %22dir%22);%0A                %7D%0A%0A                Tooltip.generateTooltip(context, selectBooleanCheckbox, rw);%0A%0A                //rw.writeAttribute(%22class%22, %22checkbox%22, %22class%22);%0A                rw.startElement(%22label%22, selectBooleanCheckbox);%0A                writeAttribute(rw, %22class%22, getErrorAndRequiredClass(selectBooleanCheckbox, clientId));%0A%0A                rw.startElement(%22input%22, selectBooleanCheckbox);%0A        %7D%0A%0A%0A
 %09/**%0A%09 *

Remove unneeded class checkbox from Switch component div ( #488 )