net.sf.click.control
Class RadioGroup

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

public class RadioGroup
extends Field

Provides a RadioGroup control.

Radio Group Red Green Blue
The RadioGroup control provides a Field for containing grouped Radio buttons. Radio controls added to a RadioGroup will have their name set to that of the RadioGroup. This will ensure the buttons will toggle together so that only one button is selected at a time.

RadioGroup Example

The example below illustrates a RadioGroup being added to a form.
 public class Purchase extends Page {

     public Form form = new Form();

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

     public Purchase() {
         radioGroup.add(new Radio("STD", "Standard "));
         radioGroup.add(new Radio("PRO", "Protective "));
         radioGroup.add(new Radio("GFT", "Gift Wrap "));
         radioGroup.setValue("STD");
         radioGroup.setVerticalLayout(true);
         form.add(radioGroup);

         ..
     }
 } 
This radio group field would be render as:
Packaging Standard
Protective
Gift Wrap
See also W3C HTML reference INPUT

Author:
Malcolm Edgar
See Also:
Radio, Serialized Form

Field Summary
protected  boolean isVerticalLayout
          The layout is vertical flag (default false).
protected  List radioList
          The list of Radio controls.
protected static String VALIDATE_RADIOGROUP_FUNCTION
          The field validation JavaScript function template.
 
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
RadioGroup()
          Create a RadioGroup field with no name.
RadioGroup(String name)
          Create a RadioGroup with the given name.
RadioGroup(String name, boolean required)
          Create a RadioGroup with the given name and required status.
RadioGroup(String name, String label)
          Create a RadioGroup with the given name and label.
RadioGroup(String name, String label, boolean required)
          Create a RadioGroup with the given name, label and required status.
 
Method Summary
 void add(Radio radio)
          Add the given radio to the radio group.
 void addAll(Collection options)
          Add the given collection Radio item options to the RadioGroup.
 void addAll(Collection objects, String value, String label)
          Add the given collection of objects to the RadioGroup, creating new Radio instances based on the object properties specified by value and label.
 void addAll(Map options)
          Add the given Map of radio values and labels to the RadioGroup.
 int getControlSizeEst()
          Return the estimated rendered control size in characters.
 String getFocusJavaScript()
          Return the RadioGroup focus JavaScript.
 List getRadioList()
          Return the list of radio controls.
 String getValidationJavaScript()
          Return the RadioGroup JavaScript client side validation function.
 boolean hasRadios()
          Return true if RadioGroup has Radio controls, or false otherwise.
 boolean isVerticalLayout()
          Return true if the radio control layout is vertical.
 void onDestroy()
          This method does nothing.
 void onInit()
          This method does nothing.
 boolean onProcess()
          Process the request Context setting the checked value and invoking the controls listener if defined.
 void render(HtmlStringBuffer buffer)
          Render the HTML representation of the RadioGroup.
 void setForm(Form form)
          Set the Field's the parent Form.
 void setVerticalLayout(boolean vertical)
          Set the vertical radio control layout flag.
 String toString()
          Return the HTML rendered RadioGroup string.
 void validate()
          Validate the RadioGroup request submission.
 
Methods inherited from class net.sf.click.control.Field
bindRequestValue, getError, getErrorLabel, getFocus, getForm, getHelp, getId, getLabel, getRequestValue, getTabIndex, getTextAlign, getTitle, getValidate, getValue, getValueObject, getWidth, isDisabled, isHidden, isReadonly, isRequired, isValid, setDisabled, setError, setErrorMessage, setErrorMessage, setErrorMessage, setErrorMessage, setFocus, setHelp, setLabel, setListener, setParent, setReadonly, setRequired, setTabIndex, setTextAlign, setTitle, setValidate, setValue, setValueObject, setWidth
 
Methods inherited from class net.sf.click.control.AbstractControl
addStyleClass, appendAttributes, getActionListener, getAttribute, getAttributes, getContext, getHtmlImports, getMessage, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, getTag, hasAttribute, hasAttributes, hasStyles, onDeploy, onRender, registerActionEvent, removeStyleClass, renderTagBegin, renderTagEnd, setActionListener, setAttribute, setId, setName, setStyle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VALIDATE_RADIOGROUP_FUNCTION

protected static final String VALIDATE_RADIOGROUP_FUNCTION
The field validation JavaScript function template. The function template arguments are:

See Also:
Constant Field Values

radioList

protected List radioList
The list of Radio controls.


isVerticalLayout

protected boolean isVerticalLayout
The layout is vertical flag (default false). If the layout is vertical each Radio controls is rendered on a new line using the <br> tag.

Constructor Detail

RadioGroup

public RadioGroup(String name)
Create a RadioGroup with the given name.

Parameters:
name - the name of the field

RadioGroup

public RadioGroup(String name,
                  boolean required)
Create a RadioGroup with the given name and required status.

Parameters:
name - the name of the field
required - the field required status

RadioGroup

public RadioGroup(String name,
                  String label)
Create a RadioGroup with the given name and label.

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

RadioGroup

public RadioGroup(String name,
                  String label,
                  boolean required)
Create a RadioGroup with the given name, label and required status.

Parameters:
name - the name of the field
label - the label of the field
required - the field required status

RadioGroup

public RadioGroup()
Create a RadioGroup field with no name.

Please note the control's name must be defined before it is valid.

Method Detail

add

public void add(Radio radio)
Add the given radio to the radio group. When the radio is added to the group it will use its parent RadioGroup's name when rendering if it has not already been set.

Parameters:
radio - the radio control to add to the radio group
Throws:
IllegalArgumentException - if the radio parameter is null

addAll

public void addAll(Collection options)
Add the given collection Radio item options to the RadioGroup.

Parameters:
options - the collection of Radio items to add
Throws:
IllegalArgumentException - if options is null

addAll

public void addAll(Map options)
Add the given Map of radio values and labels to the RadioGroup. The Map entry key will be used as the radio value and the Map entry value will be used as the radio label.

It is recommended that LinkedHashMap is used as the Map parameter to maintain the order of the radio items.

Parameters:
options - the Map of radio option values and labels to add
Throws:
IllegalArgumentException - if options is null

addAll

public void addAll(Collection objects,
                   String value,
                   String label)
Add the given collection of objects to the RadioGroup, creating new Radio instances based on the object properties specified by value and label.
 RadioGroup radioGroup = new RadioGroup("type", "Type:");
 radioGroup.addAll(getCustomerService().getCustomerTypes(), "id", "name");
 form.add(select); 

Parameters:
objects - the collection of objects to render as radio options
value - the name of the object property to render as the Radio value
label - the name of the object property to render as the Radio label
Throws:
IllegalArgumentException - if options, value or label parameter is null

getFocusJavaScript

public String getFocusJavaScript()
Return the RadioGroup focus JavaScript.

Overrides:
getFocusJavaScript in class Field
Returns:
the RadioGroup focus JavaScript

setForm

public void setForm(Form form)
Description copied from class: Field
Set the Field's the parent Form.

Overrides:
setForm in class Field
Parameters:
form - Field's parent Form
See Also:
Field.setForm(Form)

isVerticalLayout

public boolean isVerticalLayout()
Return true if the radio control layout is vertical.

Returns:
true if the radio control layout is vertical

setVerticalLayout

public void setVerticalLayout(boolean vertical)
Set the vertical radio control layout flag.

Parameters:
vertical - the vertical layout flag

getRadioList

public List getRadioList()
Return the list of radio controls.

Returns:
the list of radio controls

hasRadios

public boolean hasRadios()
Return true if RadioGroup has Radio controls, or false otherwise.

Returns:
true if RadioGroup has Radio controls, or false otherwise

getValidationJavaScript

public String getValidationJavaScript()
Return the RadioGroup JavaScript client side validation function.

Overrides:
getValidationJavaScript in class Field
Returns:
the field JavaScript client side validation function

onInit

public void onInit()
Description copied from class: Field
This method does nothing. Subclasses may override this method to perform additional initialization.

Specified by:
onInit in interface Control
Overrides:
onInit in class Field
See Also:
Control.onInit()

onProcess

public boolean onProcess()
Process the request Context setting the checked value 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
See Also:
Control.onProcess()

onDestroy

public void onDestroy()
Description copied from class: AbstractControl
This method does nothing. Subclasses may override this method to perform clean up any resources.

Specified by:
onDestroy in interface Control
Overrides:
onDestroy in class AbstractControl
See Also:
Control.onDestroy()

getControlSizeEst

public int getControlSizeEst()
Description copied from class: AbstractControl
Return the estimated rendered control size in characters.

Overrides:
getControlSizeEst in class AbstractControl
Returns:
the estimated rendered control size in characters
See Also:
AbstractControl.getControlSizeEst()

render

public void render(HtmlStringBuffer buffer)
Render the HTML representation of the RadioGroup.

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:
toString()

toString

public String toString()
Return the HTML rendered RadioGroup string.

Overrides:
toString in class AbstractControl
Returns:
the HTML rendered RadioGroup string
See Also:
Object.toString()

validate

public void validate()
Validate the RadioGroup request submission.

A field error message is displayed if a validation error occurs. These messages are defined in the resource bundle:

net.sf.click.control.MessageProperties

Error message bundle key names include:

  • field-required-error

Overrides:
validate in class Field