Class WRadioButton

  • All Implemented Interfaces:
    AjaxTarget, BeanAware, BeanBound, BeanProviderBound, DataBound, Disableable, Labelable, SubordinateTarget, WComponent, WebComponent, Serializable

    public class WRadioButton
    extends WBeanComponent
    implements AjaxTarget, SubordinateTarget, Disableable, Labelable

    A WRadioButton is a wcomponent used to display a radio button and must be used with a RadioButtonGroup.

    A WRadioButton instance can only be created by using the addRadioButton(value) method or addRadioButton() method. Call one of these methods to get an instance of a radio button and then add the radio button to the required location in the UI. Each radio button added to a group must have a unique value for that group.

    If the value of the radio button is known when creating its instance, then use the addRadioButton(Object).

    If a radio button needs to be used in a repeating component and will have different values depending on its context, then use the addRadioButton(). Radio buttons used with a WRepeater will get their value from the "bean" associated to the row in the repeater. By default, the bean property for the radio button will be set to ".", but this can be overridden by calling WBeanComponent.setBeanProperty(String) on the radio button instance.

    For the radio button group to work correctly, it is important that each radio button in the group has a unique value. The radio button group uses the String representation of the radio button's value to identify which button has been selected. As the string representation of the radio button's value is sent to the client, be mindful that it should not be too large.

    To determine if a WRadioButton has been selected use the isSelected method. Alternatively, you can call the getSelectedValue method on the RadioButtonGroup which will return the value associated with the WRadioButton which is currently selected.

    Since:
    1.0.0
    Author:
    James Gifford, Jonathan Austin
    See Also:
    Serialized Form
    • Method Detail

      • handleRequest

        public void handleRequest​(Request request)
        This method will only process the request if the value for the group matches the button's value.
        Specified by:
        handleRequest in interface WComponent
        Overrides:
        handleRequest in class AbstractWComponent
        Parameters:
        request - the request being processed.
      • getGroupName

        public String getGroupName()
        Retrieves the name of the RadioButtonGroup that this button is associated with.
        Returns:
        the group name, or null if not associated to a group.
      • isSelected

        public boolean isSelected()
        Returns:
        true if the radio button is selected.
      • setSelected

        public void setSelected​(boolean selected)
        Sets whether the radio button is selected.
        Parameters:
        selected - true if the button should be selected, false if not
      • getValue

        public String getValue()
        Retrieves the radio button's value.

        The radio button group uses the String value of the radio button's value to identify which button has been selected. As the string representation of the radio button's value is sent to the client, be mindful that it should not be too large.

        Returns:
        the radio button's value.
      • isMandatory

        public boolean isMandatory()
        Indicates whether or not the radio button group is mandatory for a specific user.
        Returns:
        true if the radio button group is mandatory, false otherwise.
      • isSubmitOnChange

        @Deprecated
        public boolean isSubmitOnChange()
        Deprecated.
        1.4.0 as it results in a level A accessibility problem See https://www.w3.org/TR/UNDERSTANDING-WCAG20/consistent-behavior-unpredictable-change.html.
        Indicates whether selection of the radio button should trigger a form submit.
        Returns:
        true if selection should trigger a submit.
      • getGroup

        public RadioButtonGroup getGroup()
        Retrieves the RadioButtonGroup associated with this radio button.
        Returns:
        the associated RadioButtonGroup
      • isDisabled

        public boolean isDisabled()
        Indicates whether the radio button is disabled.
        Specified by:
        isDisabled in interface Disableable
        Returns:
        true if the input is disabled, otherwise false.
      • setDisabled

        public void setDisabled​(boolean disabled)
        Sets whether the radio button is disabled.
        Specified by:
        setDisabled in interface Disableable
        Parameters:
        disabled - if true, the input is disabled. If false, it is enabled.
      • isReadOnly

        public boolean isReadOnly()
        Indicates whether the radio button is read only in the given context.
        Returns:
        true if the input is read only, otherwise false.
      • setReadOnly

        public void setReadOnly​(boolean readOnly)
        Sets whether the radio button is read only.
        Parameters:
        readOnly - if true, the input is read only. If false, it is editable.