com.sun.rave.web.ui.component
Class RadioButton

java.lang.Object
  extended byjavax.faces.component.UIComponent
      extended byjavax.faces.component.UIComponentBase
          extended byjavax.faces.component.UIOutput
              extended byjavax.faces.component.UIInput
                  extended bycom.sun.rave.web.ui.component.SelectorBase
                      extended bycom.sun.rave.web.ui.component.Selector
                          extended bycom.sun.rave.web.ui.component.RbCbSelectorBase
                              extended bycom.sun.rave.web.ui.component.RbCbSelector
                                  extended bycom.sun.rave.web.ui.component.RadioButtonBase
                                      extended bycom.sun.rave.web.ui.component.RadioButton
All Implemented Interfaces:
javax.faces.component.EditableValueHolder, SelectorManager, javax.faces.component.StateHolder, javax.faces.component.ValueHolder

public class RadioButton
extends RadioButtonBase

A component that represents a radio button.

The RadioButton can be used as a single radio button or one radio button among a group of radio button. A group of radio button represents a multiple selection list which can have any number of radio button selected, or none selected. A radio button can represent a Boolean value, a String value, or a developer defined Object value.

Detecting a selected radio button

The RadioButton uses both the selected and selectedValue properties to pass information about the radio button's selection status. The selected property is used to indicate that the radio button is selected. The selectedValue property is used to pass a data value, a string by default, for the radio button. A radio button is considered to be selected when the value of the selected property is equal to the value of the selectedValue property. A radio button can be initally selected by assigning the same value to the selectedValue and the selected properties. isChecked is called to determine if this RadioButton is selected.

If the selectedValue property is not specified or its value is null then the radio button behaves like a boolean control. If the radio button is selected, the value of the selected property is a true Boolean instance. If the radio button is not selected, the value of the selected property will be a false Boolean instance.

Note that a value binding expression that evaluates to a primitive boolean value can be assigned to the selected property. Proper type coercion from Boolean to boolean occurs.

When a radio button is part of a group, the selected radio button is maintained as a request attribute in the RequestMap. The name of the attribute is the value of the radio button's name property. The request attribute value is the value of the selectedValue property of the selected radio button. The selected property of the selected radio button within the group, will also contain the value of the selectedValue property of the respective selected radio button. If no radio buttons are selected, no request attribute is created, however at least one radio button must be selected.

Note that the RadioButton does not enforce the requirement that at least one radio button must be selected. The application should ensure that this requirement is met.

Using a radio button tag as a boolean control

If the selectedValue property is not specified or its value is null then the radio button behaves like a boolean control.

To use the RadioButton as a boolean control, do not specify a value for the selectedValue property. The radio button is selected if the selected property is not null and has the value of a Boolean instance with a true value. If the radio button is not selected, then the value of the selected property is a false Boolean instance.

Note that using a boolean radio button in a group and referencing the request property for the selected radio button is not useful, since the value of the request property will be an indistinguishable true value.

Using a RadioButton to represent a developer defined value

The selectedValue property can be assigned a developer defined object value to represent the value of a selected radio button. If the radio button is selected, the value of the selected property is assigned the value of the selectedValue property.

If the value of the selectedValue property is a developer defined object, a Converter must be registered to convert to and from a String value.
In addition the object must support an equals method that returns true when the value of the selectedValue property is compared to the selected property value in order to detect a selected radio button.

Using a RadioButton as one control in a group

The name property determines whether a radio button is part of a group. A radio button is treated as part of a group of radio buttons if the name property of the radio button is assigned a value equal to the name property of the other radio buttons in the group. In other words, all radio button of a group have the same name property value. The group behaves like a single selection list, where only one radio button can be selected. The value of the name property must be unique within the scope of the Form parent containing the radio buttons.

Facets

The following facets are supported:

Add an image or label facet to the RadioButton if more control over the properties of the subcomponents is needed.

Note that if a facet is exists, RadioButton properties that would normally be assigned to the created subcomponent, will not be assigned to the facet

Note that unexpected layout of the RadioButton may occur if the component specified by the facet is not a ImageComponent for the image facet or Label for the label facet.

ImageComponent and Label subcomponents

An image and a label may be associated with the RadioButton.
If the imageURL property is not null and an image facet does not exist then a ImageComponent component is created.
If the label property is not null and a label facet does not exist then a Label component is created.

The following RadioButton properties are assigned to the subcomponents only if a facet does not exist.
For the ImageComponent subcomponent

For the Label subcomponent

Note that if a value binding exists for one of the RadioButton properties mentioned above, the value binding is set on the subcomponent for that property.


Field Summary
 
Fields inherited from class com.sun.rave.web.ui.component.RbCbSelector
IMAGE_FACET, LABEL_FACET
 
Fields inherited from class com.sun.rave.web.ui.component.Selector
valueTypeEvaluator
 
Fields inherited from class javax.faces.component.UIInput
COMPONENT_FAMILY, COMPONENT_TYPE, CONVERSION_MESSAGE_ID, REQUIRED_MESSAGE_ID
 
Constructor Summary
RadioButton()
          Construct a RadioButton instance.
 
Method Summary
protected  void addToRequestMap(javax.faces.context.FacesContext context, java.lang.String groupName)
          Implemented by subclasses in order to reflect the selection state of this component id part of a group.
static java.lang.Object getSelected(java.lang.String name)
          Return the value of the selectedValue property of the selected radio button in the group of radio buttons identified by the name parameter.
 void validate(javax.faces.context.FacesContext context)
          Update the request parameter that holds the value of the selectedValue property of the selected radio button.
 
Methods inherited from class com.sun.rave.web.ui.component.RadioButtonBase
getFamily, getLabelLevel, restoreState, saveState, setLabelLevel
 
Methods inherited from class com.sun.rave.web.ui.component.RbCbSelector
createImageComponent, createLabelComponent, encodeBegin, getConvertedValue, getConvertedValue, getImageComponent, getLabelComponent, getSelectedValue, isChecked
 
Methods inherited from class com.sun.rave.web.ui.component.RbCbSelectorBase
getImageURL, getName, getSelected, getValueBinding, setImageURL, setName, setSelected, setSelectedValue, setValueBinding
 
Methods inherited from class com.sun.rave.web.ui.component.Selector
compareValues, getRendersChildren, getValueAsReadOnly, isMultiple, setMultiple, toString
 
Methods inherited from class com.sun.rave.web.ui.component.SelectorBase
getItems, getLabel, getOnBlur, getOnChange, getOnClick, getOnDblClick, getOnFocus, getOnKeyDown, getOnKeyPress, getOnKeyUp, getOnMouseDown, getOnMouseMove, getOnMouseOut, getOnMouseOver, getOnMouseUp, getOnSelect, getStyle, getStyleClass, getTabIndex, getToolTip, isDisabled, isReadOnly, isVisible, setDisabled, setItems, setLabel, setOnBlur, setOnChange, setOnClick, setOnDblClick, setOnFocus, setOnKeyDown, setOnKeyPress, setOnKeyUp, setOnMouseDown, setOnMouseMove, setOnMouseOut, setOnMouseOver, setOnMouseUp, setOnSelect, setReadOnly, setStyle, setStyleClass, setTabIndex, setToolTip, setVisible
 
Methods inherited from class javax.faces.component.UIInput
addValidator, addValueChangeListener, broadcast, decode, getSubmittedValue, getValidator, getValidators, getValueChangeListener, getValueChangeListeners, isImmediate, isLocalValueSet, isRequired, isValid, processDecodes, processUpdates, processValidators, removeValidator, removeValueChangeListener, setImmediate, setLocalValueSet, setRequired, setSubmittedValue, setValid, setValidator, setValue, setValueChangeListener, updateModel, validateValue
 
Methods inherited from class javax.faces.component.UIOutput
getConverter, getLocalValue, getValue, setConverter
 
Methods inherited from class javax.faces.component.UIComponentBase
addFacesListener, encodeChildren, encodeEnd, findComponent, getAttributes, getChildCount, getChildren, getClientId, getFacesContext, getFacesListeners, getFacet, getFacets, getFacetsAndChildren, getId, getParent, getRenderer, getRendererType, isRendered, isTransient, processRestoreState, processSaveState, queueEvent, removeFacesListener, restoreAttachedState, saveAttachedState, setId, setParent, setRendered, setRendererType, setTransient
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.sun.rave.web.ui.component.SelectorManager
getClientId, getOnChange, getStyle, getStyleClass, getTabIndex, isDisabled, isReadOnly
 
Methods inherited from interface javax.faces.component.ValueHolder
getConverter, getLocalValue, getValue, setConverter
 

Constructor Detail

RadioButton

public RadioButton()
Construct a RadioButton instance.

Method Detail

getSelected

public static java.lang.Object getSelected(java.lang.String name)
Return the value of the selectedValue property of the selected radio button in the group of radio buttons identified by the name parameter. A RadioButton is one of a group of radio buttons if more than on radio button has the same value for the name property.
When one of the radio buttons among that group is selected, the value of its selectedValue property is maintained in a request attribute identified by the value of its name property.

Parameters:
name - the value a RadioButton name property.

validate

public void validate(javax.faces.context.FacesContext context)

Update the request parameter that holds the value of the selectedValue property of the selected radio button.

If the name property has been set a request attribute is created. The value of the name property will be used for the request attribute name and the value of the request attribute will be the value of the selectedValue property.

The request attribute described above is available during a ValueChangeEvent.

Parameters:
context - The context of this request.

addToRequestMap

protected void addToRequestMap(javax.faces.context.FacesContext context,
                               java.lang.String groupName)
Description copied from class: RbCbSelector
Implemented by subclasses in order to reflect the selection state of this component id part of a group. This method is called if the component is part of a group.

Overrides:
addToRequestMap in class RbCbSelector
Parameters:
context - the context for this request.
groupName - the value of the name property.