All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.webui.jsf.renderkit.html.RadioButtonGroupRenderer Maven / Gradle / Ivy

There is a newer version: 4.4.0.1
Show newest version
/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2007-2018 Oracle and/or its affiliates. All rights reserved.
 *
 * The contents of this file are subject to the terms of either the GNU
 * General Public License Version 2 only ("GPL") or the Common Development
 * and Distribution License("CDDL") (collectively, the "License").  You
 * may not use this file except in compliance with the License.  You can
 * obtain a copy of the License at
 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
 * or LICENSE.txt.  See the License for the specific
 * language governing permissions and limitations under the License.
 *
 * When distributing the software, include this License Header Notice in each
 * file and include the License file at LICENSE.txt.
 *
 * GPL Classpath Exception:
 * Oracle designates this particular file as subject to the "Classpath"
 * exception as provided by Oracle in the GPL Version 2 section of the License
 * file that accompanied this code.
 *
 * Modifications:
 * If applicable, add the following below the License Header, with the fields
 * enclosed by brackets [] replaced by your own identifying information:
 * "Portions Copyright [year] [name of copyright owner]"
 *
 * Contributor(s):
 * If you wish your version of this file to be governed by only the CDDL or
 * only the GPL Version 2, indicate your decision by adding "[Contributor]
 * elects to include this software in this distribution under the [CDDL or GPL
 * Version 2] license."  If you don't indicate a single choice of license, a
 * recipient has the option to distribute your version of this file under
 * either the CDDL, the GPL Version 2 or to extend the choice of license to
 * its licensees as provided above.  However, if you add GPL Version 2 code
 * and therefore, elected the GPL Version 2 license, then the option applies
 * only if the new code is made subject to such option by the copyright
 * holder.
 */

package com.sun.webui.jsf.renderkit.html;

import com.sun.faces.annotation.Renderer;
import java.io.IOException;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import com.sun.webui.jsf.component.RadioButton;
import com.sun.webui.jsf.component.RadioButtonGroup;
import com.sun.webui.jsf.model.Option;
import com.sun.webui.theme.Theme;
import com.sun.webui.jsf.theme.ThemeStyles;
import com.sun.webui.jsf.util.ConversionUtilities;
import com.sun.webui.jsf.util.ThemeUtilities;

/**
 * The RadioButtonRenderer renders a RadioButtonGroup
 * component as set of radio buttons. The RadioButtonGroupRenderer
 * creates an instance of RadioButton for each
 * Option instance in the Array, Map, or
 * Collection returned by the RadioButtonGroup
 * getItems() method and renders them. It also
 * creates a Label component and renders it as the label for the
 * group.
 * 

* Only one radio button may be selected at any time and one radio button * must always be selected. The value of the RadioButtonGroup * will determine which radio button shall be initially selected. * Subsequently, the RadioButtonGroup's value holds the * currently selected radio button value. *

*

* The radio buttons are rendered as a single column or some number of * rows and columns. The rows and columns are rendered as a table as * defined by the {@link com.sun.webui.jsf.renderkit.html.RowColumnRenderer} superclass. * The elements * that make up the radio button occupy a cell in the table. * The style class selector for the group elements is identified by a java * constants defined in the {@link com.sun.webui.jsf.theme.ThemeStyles} class. *

*
    *
  • RADIOBUTTON_GROUP for the TABLE element.
  • *
  • RADIOBUTTON_GROUP_CAPTION for the TD element containing the group * label
  • *
  • RADIOBUTTON_GROUP_LABEL for the LABEL element used as the CAPTION
  • *
  • RADIOBUTTON_GROUP_LABEL_DISABLED for the LABEL used as the CAPTION if * the group is disabled
  • *
  • RADIOBUTTON_GROUP_ROW_EVEN for even TR elements
  • *
  • RADIOBUTTON_GROUP_ROW_ODD for odd TR elements
  • *
  • RADIOBUTTON_GROUP_CELL_EVEN for even TD elements
  • *
  • RADIOBUTTON_GROUP_CELL_ODD for odd TD elements
  • *
  • RADIOBUTTON for the INPUT element
  • *
  • RADIOBUTTON_DISABLED for the INPUT element for disabled radio * button
  • *
  • RADIOBUTTON_LABEL for a LABEL element of a radio button
  • *
  • RADIOBUTTON_LABEL_DISABLED for a LABEL element of a disabled radio * button
  • *
  • RADIOBUTTON_IMAGE for an IMG element of a radio button
  • *
  • RADIOBUTTON_IMAGE_DISABLED for an IMG element of a disabled radio * button
  • *
*

* The name property of each radio button is the component id of * the RadioButtonGroup instance. The id of a * RadioButton component is rbgrpid_N where * rbgrpid is the id of the * RadioButtonGroup instance and _N is the nth * radio button. *

*

* The RadioButtonGroup is decoded by identifying the * RadioButtonGroup instance component id which is * returned as a request parameter. It represents the name attribute * of the selected radio button's <input> element. The value of * the identified request parameter is assigned as the submitted value of the * RadioButtonGroup component. *

*

* If the items property of the RadioButtonGroup is null or * zero length no output is produced. *

* */ @Renderer(@Renderer.Renders(componentFamily = "com.sun.webui.jsf.RadioButtonGroup")) //FIXME check about making SelectGroupRenderer a public abstract class public class RadioButtonGroupRenderer extends SelectorGroupRenderer { private final String MSG_COMPONENT_NOT_RADIOBUTTONGROUP = "RadioButtonGroupRender only renders RadioButtonGroup components."; //NOI18N /** * Creates a new instance of RadioButtonGroupRenderer */ public RadioButtonGroupRenderer() { super(); } /** * Ensure that the component to be rendered is a RadioButtonGroup instance. * Actual rendering occurs during renderEnd * * @param context FacesContext for the request we are processing. * @param component UIComponent to be decoded. */ @Override public void renderStart(FacesContext context, UIComponent component, ResponseWriter writer) throws IOException { // Bail out if the component is not a RadioButtonGroup component. if (!(component instanceof RadioButtonGroup)) { throw new IllegalArgumentException(MSG_COMPONENT_NOT_RADIOBUTTONGROUP); } } /** * RadioButtonGroupRenderer renders the entire RadioButtonGroup * component within the renderEnd method. * * @param context FacesContext for the request we are processing. * @param component UIComponent to be decoded. */ @Override public void renderEnd(FacesContext context, UIComponent component, ResponseWriter writer) throws IOException { // Use only the cols value. If not valid render a single column. // If there are more items than columns, render additional rows. // RadioButtonGroup rbgrp = (RadioButtonGroup) component; Theme theme = ThemeUtilities.getTheme(context); renderSelectorGroup(context, component, theme, writer, rbgrp.getColumns()); } /** * Return a RadioButton component to render. * * @param context FacesContext for the current request * @param component CheckboxGroup component rendered * @param theme Theme for the component * @param option the Option being rendered. */ protected UIComponent getSelectorComponent(FacesContext context, UIComponent component, Theme theme, String id, Option option) { RadioButtonGroup rbgrp = (RadioButtonGroup) component; RadioButton rb = new RadioButton(); rb.setId(id); rb.setParent(component); rb.setName(rbgrp.getClientId(context)); rb.setToolTip(option.getTooltip()); rb.setImageURL(option.getImage()); rb.setSelectedValue(option.getValue()); rb.setLabel(option.getLabel()); rb.setDisabled(rbgrp.isDisabled()); rb.setReadOnly(rbgrp.isReadOnly()); rb.setTabIndex(rbgrp.getTabIndex()); // mbohm 6300361,6300362 // transfer event attributes from cbgrp to cb // see RowColumnRenderer.renderRowColumnLayout transferEventAttributes(rbgrp, rb); // Default to not selected // rb.setSelected(null); // Need to check the submittedValue for immediate condition // String[] subValue = (String[]) rbgrp.getSubmittedValue(); if (subValue == null) { if (isSelected(option, rbgrp.getSelected())) { rb.setSelected(rb.getSelectedValue()); } } else if (subValue.length != 0) { Object selectedValue = rb.getSelectedValue(); String selectedValueAsString = ConversionUtilities.convertValueToString(component, selectedValue); if (subValue[0] != null && subValue[0].equals(selectedValueAsString)) { rb.setSelected(rb.getSelectedValue()); } } return rb; } /** * Return true if the item argument is the currently * selected radio button. Equality is determined by the equals * method of the object instance stored as the value of * item. Return false otherwise. * * @param item the current radio button being rendered. * @param currentValue the value of the current selected radio button. */ private boolean isSelected(Option item, Object currentValue) { return currentValue != null && item.getValue() != null && item.getValue().equals(currentValue); } protected String[] styles = { ThemeStyles.RADIOBUTTON_GROUP, /* GRP */ ThemeStyles.RADIOBUTTON_GROUP_CAPTION, /* GRP_CAPTION */ ThemeStyles.RADIOBUTTON_GROUP_LABEL, /* GRP_LABEL */ ThemeStyles.RADIOBUTTON_GROUP_LABEL_DISABLED, /* GRP_CAPTION_DIS */ ThemeStyles.RADIOBUTTON_GROUP_ROW_EVEN, /* GRP_ROW_EVEN */ ThemeStyles.RADIOBUTTON_GROUP_ROW_ODD, /* GRP_ROW_EVEN */ ThemeStyles.RADIOBUTTON_GROUP_CELL_EVEN,/* GRP_CELL_EVEN */ ThemeStyles.RADIOBUTTON_GROUP_CELL_ODD, /* GRP_CELL_ODD */ ThemeStyles.RADIOBUTTON, /* INPUT */ ThemeStyles.RADIOBUTTON_DISABLED, /* INPUT_DIS */ ThemeStyles.RADIOBUTTON_LABEL, /* LABEL */ ThemeStyles.RADIOBUTTON_LABEL_DISABLED, /* LABEL_DIS */ ThemeStyles.RADIOBUTTON_IMAGE, /* IMAGE */ ThemeStyles.RADIOBUTTON_IMAGE_DISABLED, /* IMAGE_DIS */ ThemeStyles.LABEL_LEVEL_ONE_TEXT, /* LABEL_LVL1 */ ThemeStyles.LABEL_LEVEL_TWO_TEXT, /* LABEL_LVL2 */ ThemeStyles.LABEL_LEVEL_THREE_TEXT /* LABLE_LVL3 */}; /** * Return style constants for a RadioButton component. */ protected String[] getStyles() { return styles; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy