net.sf.click.control
Class Radio

java.lang.Object
  extended bynet.sf.click.control.AbstractControl
      extended bynet.sf.click.control.Field
          extended bynet.sf.click.control.Radio
All Implemented Interfaces:
Control, Serializable

public class Radio
extends Field

Provides a Radio control:   <input type='radio'>.

Radio
The Radio control is generally used within a RadioGroup, for an code example pleasse see the RadioGroup Javadoc example. When used with a RadioGroup the Radio control will derrive its name from the parent RadioGroup, if the Radio's name is not defined.

See also W3C HTML reference INPUT

Author:
Malcolm Edgar
See Also:
RadioGroup, Serialized Form

Field Summary
protected  boolean checked
          The field checked value.
 
Fields inherited from class net.sf.click.control.Field
disabled, error, focus, form, help, label, readonly, required, tabindex, title, validate, value
 
Fields inherited from class net.sf.click.control.AbstractControl
actionListener, attributes, listener, listenerMethod, messages, name, parent, styles
 
Fields inherited from interface net.sf.click.Control
CONTROL_MESSAGES
 
Constructor Summary
Radio()
          Create an Radio field with no name defined.
Radio(String value)
          Create a radio field with the given value.
Radio(String value, String label)
          Create a radio field with the given value and label.
Radio(String value, String label, String name)
          Create a radio field with the given value, label and name.
 
Method Summary
 void bindRequestValue()
          Bind the request submission, setting the Field checked property if defined in the request.
 String getId()
          Return the Radio field id attribute.
 String getLabel()
          Return the field display label.
 String getName()
          Return the name of the Radio field.
 String getTag()
          Return the radio's html tag: input.
 String getType()
          Return the input type: 'radio'.
 boolean isChecked()
          Return true if the radio is checked, or false otherwise.
 boolean onProcess()
          Process the request Context setting the checked value if selected and invoking the controls listener if defined.
 void render(HtmlStringBuffer buffer)
          Render a HTML Radio string.
 void setChecked(boolean value)
          Set the selected value of the radio.
 void setParent(Object parent)
          Set the parent of the Field.
 void setValue(String value)
          Set the radio value, setting the checked status if given value is the same as the radio field value.
 
Methods inherited from class net.sf.click.control.Field
getError, getErrorLabel, getFocus, getFocusJavaScript, getForm, getHelp, getRequestValue, getTabIndex, getTextAlign, getTitle, getValidate, getValidationJavaScript, getValue, getValueObject, getWidth, isDisabled, isHidden, isReadonly, isRequired, isValid, onInit, setDisabled, setError, setErrorMessage, setErrorMessage, setErrorMessage, setErrorMessage, setFocus, setForm, setHelp, setLabel, setListener, setReadonly, setRequired, setTabIndex, setTextAlign, setTitle, setValidate, setValueObject, setWidth, validate
 
Methods inherited from class net.sf.click.control.AbstractControl
addStyleClass, appendAttributes, getActionListener, getAttribute, getAttributes, getContext, getControlSizeEst, getHtmlImports, getMessage, getMessage, getMessage, getMessages, getPage, getParent, getStyle, getStyles, hasAttribute, hasAttributes, hasStyles, onDeploy, onDestroy, onRender, registerActionEvent, removeStyleClass, renderTagBegin, renderTagEnd, setActionListener, setAttribute, setId, setName, setStyle, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

checked

protected boolean checked
The field checked value.

Constructor Detail

Radio

public Radio(String value)
Create a radio field with the given value.

Parameters:
value - the label of the field

Radio

public Radio(String value,
             String label)
Create a radio field with the given value and label.

Parameters:
value - the label of the field
label - the name of the field

Radio

public Radio(String value,
             String label,
             String name)
Create a radio field with the given value, label and name.

Parameters:
value - the label of the field
label - the label of the field
name - the name of the field

Radio

public Radio()
Create an Radio field with no name defined.

Method Detail

getTag

public String getTag()
Return the radio's html tag: input.

Overrides:
getTag in class AbstractControl
Returns:
this controls html tag
See Also:
AbstractControl.getTag()

isChecked

public boolean isChecked()
Return true if the radio is checked, or false otherwise.

Returns:
true if the radio is checked.

setChecked

public void setChecked(boolean value)
Set the selected value of the radio.

Parameters:
value - the selected value

getId

public String getId()
Return the Radio field id attribute.

Specified by:
getId in interface Control
Overrides:
getId in class Field
Returns:
HTML element identifier attribute "id" value
See Also:
Control.getId()

setParent

public void setParent(Object parent)
Set the parent of the Field.

Specified by:
setParent in interface Control
Overrides:
setParent in class Field
Parameters:
parent - the parent of the Control
Throws:
IllegalArgumentException - if the given parent instance is referencing this object: if (parent == this)
See Also:
Control.setParent(Object)

getLabel

public String getLabel()
Return the field display label.

If the label value is null, this method will attempt to find a localized label message in the parent messages using the key:

If the Radio name attribute is not null:

super.getName() + ".label"
If the Radio name attribute is null and the parent of the Radio is the RadioGroup:
parent.getName() + "." + getValue() + ".label"
If not found then the message will be looked up in the /click-control.properties file using the same key. If a value still cannot be found then the Field name will be the radio value.

For examle given a CustomerPage with the properties file CustomerPage.properties:

 gender.M.label=Male
 gender.F.label=Female 
The page Radio code:
 public class CustomerPage extends Page {

     public Form form = new Form();

     private RadioGroup radioGroup = new RadioGroup("gender");

     public CustomerPage() {
         radioGroup.add(new Radio("M"));
         radioGroup.add(new Radio("F"));
         form.add(radioGroup);

         ..
     }
 } 
Will render the Radio label properties as:
 <input type="radio" name="gender" value="M"><label>Male</label></label><br/>
 <input type="radio" name="gender" value="F"><label>Female</label></label> 

Overrides:
getLabel in class Field
Returns:
the display label of the Field

getName

public String getName()
Return the name of the Radio field. If the Radio name attribute has not been explicitly set, this method will return its parent RadioGroup's name if defined.

Specified by:
getName in interface Control
Overrides:
getName in class AbstractControl
Returns:
the name of the control
See Also:
Control.getName()

getType

public String getType()
Return the input type: 'radio'.

Returns:
the input type: 'radio'

setValue

public void setValue(String value)
Set the radio value, setting the checked status if given value is the same as the radio field value.

Overrides:
setValue in class Field
Parameters:
value - the Field value
See Also:
Field.setValue(String)

bindRequestValue

public void bindRequestValue()
Bind the request submission, setting the Field checked property if defined in the request.

Overrides:
bindRequestValue in class Field

onProcess

public boolean onProcess()
Process the request Context setting the checked value if selected and invoking the controls listener if defined.

Specified by:
onProcess in interface Control
Overrides:
onProcess in class Field
Returns:
true to continue Page event processing or false otherwise

render

public void render(HtmlStringBuffer buffer)
Render a HTML Radio string.

Specified by:
render in interface Control
Overrides:
render in class AbstractControl
Parameters:
buffer - the specified buffer to render the control's output to
See Also:
AbstractControl.toString()