com.sun.rave.web.ui.renderer
Class RadioButtonRenderer

java.lang.Object
  extended by javax.faces.render.Renderer
      extended by com.sun.rave.web.ui.renderer.AbstractRenderer
          extended by com.sun.rave.web.ui.renderer.RadioButtonRenderer

public class RadioButtonRenderer
extends AbstractRenderer

The RadioButtonRenderer renders a RadioButton component.

Encoding

The RadioButtonRenderer renders a RadioButton as:

The CSS selectors for the elements and components that comprise a radio button are identified by java constants defined in the ThemeStyles class.

Note that these selectors are appended to any existing selectors that may already exist on the styleClass property of the RadioButton component and the optional image and label components.

For more details on the encoding the RadioButton component see the super class RbCbRendererBase

Decoding

If the INPUT element representing a radio button is selected on the the client, the submitted request will contain a request parameter whose name is the value of the name attribute of the selected HTML INPUT element. The value of the request parameter will be the value of the value attribute of the selected HTML INPUT element.

The component being decoded is selected if the component's isDisabled and isReadOnly methods return false and:

And

If selected, a String[1] array is assigned as the component's submitted value where the single array element is the String version of the selectedValue property or "true" if the component was encoded as a boolean control.
If not selected, a String[0] array is assigned as the component's submitted value or a String[1] array where the single array element is "false" if the component was encoded as a boolean control.

If the component's isDisabled or isReadOnly methods return true no submitted value is assigned to the component, and results in a null submitted value implying the component was not submitted, and the state of the component is unchanged.

Since the RadioButtonRenderer only renders a single RadioButton component it cannot enforce that at least one radio button should be selected among a group of RadioButton components with the same name property.

If the RadioButton is selected, the selected property will be the same value as the selectedValue property. If more than one RadioButton component is encoded with the same name property and more than one RadioButton's is selectred, the last selected RadioButton component that is encoded will be appear as checked in the HTML page. Subsequently during the next submit, only the checked RadioButton component will be selected.


Field Summary
protected static int IMAGE
          The define constant indicating the style class for the IMG element.
protected static int IMAGE_DIS
          The define constant indicating the style class for a disabled IMG element.
protected static int INPUT
          The define constant indicating the style class for an INPUT element.
protected static int INPUT_DIS
          The define constant indicating the style class for a disabled INPUT element.
protected static int LABEL
          The define constant indicating the style class for the LABEL element.
protected static int LABEL_DIS
          The define constant indicating the style class for a disabled LABEL element.
static java.lang.String[] RBCB_EVENTS_ATTRIBUTES
          The list of attribute names for Rb and Cb
protected static int SPAN
          The define constant indicating the style class for for the containing span element
protected static int SPAN_DIS
          The define constant indicating the style class for for the containing span element, when disabled.
protected  java.lang.String[] styles
           
 
Fields inherited from class com.sun.rave.web.ui.renderer.AbstractRenderer
BUNDLE, EVENTS_ATTRIBUTES, I18N_ATTRIBUTES
 
Constructor Summary
RadioButtonRenderer()
          Creates a new instance of RadioButtonRenderer
 
Method Summary
 void decode(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
          Decode the RadioButton selection.
 void encodeChildren(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
          Render the child components of this UIComponent, following the rules described for encodeBegin() to acquire the appropriate value to be rendered.
 java.lang.Object getConvertedValue(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.Object submittedValue)
           Attempt to convert previously stored state information into an object of the type required for this component (optionally using the registered Converter for this component, if there is one).
protected  java.lang.String getStyle(Theme theme, int styleCode)
          Return the style class name for the structural element indicated by styleCode
protected  boolean isSelected(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
          Return true if the component is selected, false otherwise.
 void renderEnd(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, javax.faces.context.ResponseWriter writer)
          RadioButtonRenderer renders the entire RadioButton component within the renderEnd method.
protected  void renderImage(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, Theme theme, javax.faces.context.ResponseWriter writer)
          Called from renderSelection to render an IMG element for the specified itemcontrol.
protected  void renderInput(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, Theme theme, javax.faces.context.ResponseWriter writer, java.lang.String type)
          Called from renderSelection to render an INPUT element of type type for the specified component.
protected  void renderLabel(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, Theme theme, javax.faces.context.ResponseWriter writer)
          Called from renderSelection to render a LABEL.
protected  void renderSelection(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, Theme theme, javax.faces.context.ResponseWriter writer, java.lang.String type)
          Render a radio button or a checkbox.
 void renderStart(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, javax.faces.context.ResponseWriter writer)
          Ensure that the component to be rendered is a RadioButton instance.
 
Methods inherited from class com.sun.rave.web.ui.renderer.AbstractRenderer
addBooleanAttributes, addCoreAttributes, addIntegerAttributes, addStringAttributes, encodeBegin, encodeEnd, getApplication, getAsObject, getAsString, getExternalContext, getFacesContext, getSubmittedValue, isDisabled, isPortlet, isReadOnly, renderAttributes, renderMarkup, setSubmittedValue
 
Methods inherited from class javax.faces.render.Renderer
convertClientId, getRendersChildren
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

styles

protected java.lang.String[] styles

INPUT

protected static final int INPUT
The define constant indicating the style class for an INPUT element.

See Also:
Constant Field Values

INPUT_DIS

protected static final int INPUT_DIS
The define constant indicating the style class for a disabled INPUT element.

See Also:
Constant Field Values

LABEL

protected static final int LABEL
The define constant indicating the style class for the LABEL element.

See Also:
Constant Field Values

LABEL_DIS

protected static final int LABEL_DIS
The define constant indicating the style class for a disabled LABEL element.

See Also:
Constant Field Values

IMAGE

protected static final int IMAGE
The define constant indicating the style class for the IMG element.

See Also:
Constant Field Values

IMAGE_DIS

protected static final int IMAGE_DIS
The define constant indicating the style class for a disabled IMG element.

See Also:
Constant Field Values

SPAN

protected static final int SPAN
The define constant indicating the style class for for the containing span element

See Also:
Constant Field Values

SPAN_DIS

protected static final int SPAN_DIS
The define constant indicating the style class for for the containing span element, when disabled.

See Also:
Constant Field Values

RBCB_EVENTS_ATTRIBUTES

public static final java.lang.String[] RBCB_EVENTS_ATTRIBUTES

The list of attribute names for Rb and Cb

Constructor Detail

RadioButtonRenderer

public RadioButtonRenderer()
Creates a new instance of RadioButtonRenderer

Method Detail

decode

public void decode(javax.faces.context.FacesContext context,
                   javax.faces.component.UIComponent component)

Decode the RadioButton selection.

If the value of the component's name property has been set, the value is used to match a request parameter. If it has not been set the component clientId is used to match a request parameter. If a match is found, and the value of the of the request parameter matches the String value of the component's selectedValue property, the radio button is selected. The component's submitted value is assigned a String[1] array where the single array element is the matching parameter value.

If no matching request parameter or value is found, an instance of String[0] is assigned as the submitted value, meaning that this is a component was not selected.

If the component was encoded as a boolean control the value of the matching request attribute will be the component's clientId property if selected. If selected the submitted value is new String[] { "true" } and new String[] { "false" } if not selected.

It is the developer's responsibility to ensure the validity of the name property (the name attribute on the INPUT element) by ensuring that it is unique to the radio buttons for a given group within a form.

Overrides:
decode in class AbstractRenderer
Parameters:
context - FacesContext for the request we are processing.
component - The RadioButton component to be decoded.

renderStart

public void renderStart(javax.faces.context.FacesContext context,
                        javax.faces.component.UIComponent component,
                        javax.faces.context.ResponseWriter writer)
                 throws java.io.IOException
Ensure that the component to be rendered is a RadioButton instance. Actual rendering occurs during renderEnd

Overrides:
renderStart in class AbstractRenderer
Parameters:
context - FacesContext for the request we are processing.
component - UIComponent to be decoded.
writer - ResponseWriter to which the element start should be rendered
Throws:
java.io.IOException - if an input/output error occurs

renderEnd

public void renderEnd(javax.faces.context.FacesContext context,
                      javax.faces.component.UIComponent component,
                      javax.faces.context.ResponseWriter writer)
               throws java.io.IOException
RadioButtonRenderer renders the entire RadioButton component within the renderEnd method.

Overrides:
renderEnd in class AbstractRenderer
Parameters:
context - FacesContext for the request we are processing.
component - UIComponent to be decoded.
writer - ResponseWriter to which the element start should be rendered
Throws:
java.io.IOException - if an input/output error occurs

isSelected

protected boolean isSelected(javax.faces.context.FacesContext context,
                             javax.faces.component.UIComponent component)
Return true if the component is selected, false otherwise.

Parameters:
context - FacesContext for the request we are processing.
component - UIComponent to test for selected.

getStyle

protected java.lang.String getStyle(Theme theme,
                                    int styleCode)
Return the style class name for the structural element indicated by styleCode

Parameters:
theme - The Theme for this request.
styleCode - identifies the style class for the element about to be rendered.

encodeChildren

public void encodeChildren(javax.faces.context.FacesContext context,
                           javax.faces.component.UIComponent component)
                    throws java.io.IOException
Render the child components of this UIComponent, following the rules described for encodeBegin() to acquire the appropriate value to be rendered. This method will only be called if the rendersChildren property of this component is true.

Overrides:
encodeChildren in class AbstractRenderer
Parameters:
context - FacesContext for the request we are processing.
component - UIComponent to be decoded.
Throws:
java.io.IOException - if an input/output error occurs

renderSelection

protected void renderSelection(javax.faces.context.FacesContext context,
                               javax.faces.component.UIComponent component,
                               Theme theme,
                               javax.faces.context.ResponseWriter writer,
                               java.lang.String type)
                        throws java.io.IOException
Render a radio button or a checkbox.

Parameters:
context - FacesContext for the request we are processing.
component - UIComponent to be decoded.
writer - ResponseWriter to which the HTML will be output
type - the INPUT element type attribute value.
Throws:
java.io.IOException

renderInput

protected void renderInput(javax.faces.context.FacesContext context,
                           javax.faces.component.UIComponent component,
                           Theme theme,
                           javax.faces.context.ResponseWriter writer,
                           java.lang.String type)
                    throws java.io.IOException
Called from renderSelection to render an INPUT element of type type for the specified component.

Parameters:
context - FacesContext for the request we are processing.
component - UIComponent to be rendered.
writer - ResponseWriter to which the HTML will be output
type - the INPUT element type attribute value.
Throws:
java.io.IOException

renderImage

protected void renderImage(javax.faces.context.FacesContext context,
                           javax.faces.component.UIComponent component,
                           Theme theme,
                           javax.faces.context.ResponseWriter writer)
                    throws java.io.IOException
Called from renderSelection to render an IMG element for the specified itemcontrol.

Parameters:
context - FacesContext for the request we are processing.
component - UIComponent to be decoded.
writer - ResponseWriter to which the HTML will be output
Throws:
java.io.IOException

renderLabel

protected void renderLabel(javax.faces.context.FacesContext context,
                           javax.faces.component.UIComponent component,
                           Theme theme,
                           javax.faces.context.ResponseWriter writer)
                    throws java.io.IOException
Called from renderSelection to render a LABEL.

Parameters:
context - FacesContext for the request we are processing.
component - UIComponent to be decoded.
writer - ResponseWriter to which the HTML will be output
Throws:
java.io.IOException

getConvertedValue

public java.lang.Object getConvertedValue(javax.faces.context.FacesContext context,
                                          javax.faces.component.UIComponent component,
                                          java.lang.Object submittedValue)
                                   throws javax.faces.convert.ConverterException

Attempt to convert previously stored state information into an object of the type required for this component (optionally using the registered Converter for this component, if there is one). If conversion is successful, the new value is returned and if not, a ConverterException is thrown.

Overrides:
getConvertedValue in class javax.faces.render.Renderer
Parameters:
context - FacesContext for the request we are processing
component - component being renderer.
submittedValue - a value stored on the component during decode.
Throws:
javax.faces.convert.ConverterException - if the submitted value cannot be converted successfully.
java.lang.NullPointerException - if context or component is null