001/*
002 * (C) Copyright 2014 JBoss RichFaces and others.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Anahide Tchertchian
016 */
017
018package org.nuxeo.ecm.platform.ui.web.component.radio;
019
020import java.io.IOException;
021
022import javax.faces.component.UIComponent;
023import javax.faces.component.html.HtmlSelectOneRadio;
024import javax.faces.context.FacesContext;
025import javax.faces.context.ResponseWriter;
026
027import org.richfaces.renderkit.InputRendererBase;
028
029/**
030 * Renderer for a specific radio component, skipping the original rendering, that will be handled by related
031 * {@link UIRadio} component(s).
032 *
033 * @since 6.0
034 */
035public class SelectOneRadioRenderer extends InputRendererBase {
036
037    public static final String RENDERER_TYPE = SelectOneRadioRenderer.class.getName();
038
039    @Override
040    protected void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent component) throws IOException {
041        // do nothing
042    }
043
044    @Override
045    protected void doDecode(FacesContext context, UIComponent component) {
046        if (component instanceof HtmlSelectOneRadio) {
047            HtmlSelectOneRadio select = (HtmlSelectOneRadio) component;
048            if (select.isDisabled() || select.isReadonly() || !select.isRendered()) {
049                return;
050            }
051        } else if (!component.isRendered()) {
052            return;
053        }
054        super.doDecode(context, component);
055    }
056}