Class Radio

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

    public class Radio
    extends Field
    Provides a Radio control:   <input type='radio'>.
    Example
    <input type='radio' name='header' value='Radio Control'>Radio</input>
    The Radio control is generally used within a RadioGroup, for an code example please see the RadioGroup Javadoc example. When used with a RadioGroup the Radio control will derive its name from the parent RadioGroup, if the Radio's name is not defined.

    See also W3C HTML reference INPUT

    See Also:
    RadioGroup, Serialized Form
    • 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

      • 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 org.openidentityplatform.openam.click.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 org.openidentityplatform.openam.click.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 example 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 org.openidentityplatform.openam.click.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 org.openidentityplatform.openam.click.Control
        Overrides:
        onProcess in class Field
        Returns:
        true to continue Page event processing or false otherwise
        See Also:
        Control.onProcess()
      • render

        public void render​(HtmlStringBuffer buffer)
        Render a HTML Radio string.
        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:
        AbstractControl.toString()