Class RadioGroup

  • All Implemented Interfaces:
    Serializable, org.apache.click.Stateful, org.openidentityplatform.openam.click.Control

    public class RadioGroup
    extends Field
    Provides a RadioGroup control.
    Example
    Radio Group <input type='radio' name='header' value='R'>Red </input> <input type='radio' name='header' checked value='G'>Green </input> <input type='radio' name='header' value='B'>Blue</input>
    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:
    Example
    Packaging <input type='radio' name='group' checked value='STD'>Standard</input>
    <input type='radio' name='group' value='PRO'>Protective</input>
    <input type='radio' name='group' value='GFT'>Gift Wrap</input>
    See also W3C HTML reference INPUT
    See Also:
    Radio, Serialized Form
    • Field Detail

      • VALIDATE_RADIOGROUP_FUNCTION

        protected static final String VALIDATE_RADIOGROUP_FUNCTION
        The field validation JavaScript function template. The function template arguments are:
        • 0 - is the field id
        • 1 - is the name of the radio button
        • 2 - is the id of the form
        • 3 - is the Field required status
        • 4 - is the localized error message
        • 5 - is the first radio id to select
        See Also:
        Constant Field Values
      • radioList

        protected List<Radio> 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<Radio> 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<Radio> 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: AbstractControl
        This method does nothing. Subclasses may override this method to perform initialization.
        Specified by:
        onInit in interface org.openidentityplatform.openam.click.Control
        Overrides:
        onInit in class AbstractControl
        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 org.openidentityplatform.openam.click.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 org.openidentityplatform.openam.click.Control
        Overrides:
        onDestroy in class AbstractControl
        See Also:
        Control.onDestroy()
      • render

        public void render​(HtmlStringBuffer buffer)
        Render the HTML representation of the RadioGroup.
        Specified by:
        render in interface org.openidentityplatform.openam.click.Control
        Overrides:
        render in class AbstractControl
        Parameters:
        buffer - the specified buffer to render the control's output to
        See Also:
        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:

        org.apache.click.control.MessageProperties

        Error message bundle key names include:

        • select-error
        Overrides:
        validate in class Field