Class DefaultRadioButtonHandler

  • All Implemented Interfaces:
    CompositeComponentHandler<Integer,​Boolean>, ComponentHandler<Integer>

    public class DefaultRadioButtonHandler
    extends AbstractRadioButtonHandler<Integer>

    A concrete default implementation of a CompositeComponentHandler for a group of radio buttons.

    An instance of this class is used as ComponentHandler for a radio button group if no specific handler class is specified. This implementation just uses the index of the selected button in the group as data. So a Java bean acting as model for a form that contains a radio button group should have a corresponding property of type Integer for this group. Note that really Integer should be used instead of int because the value can be set to null if no radio button in the group is selected.

    Implementation note: This class is not thread-safe.

    Version:
    $Id: DefaultRadioButtonHandler.java 205 2012-01-29 18:29:57Z oheger $
    Author:
    Oliver Heger
    • Constructor Detail

      • DefaultRadioButtonHandler

        public DefaultRadioButtonHandler()
        Creates a new instance of DefaultRadioButtonHandler.
    • Method Detail

      • getButtonIndex

        protected int getButtonIndex​(Integer value)
        Returns the index of the radio button in the associated group that represents the passed in data value. Because the data value is interpreted as the selected index it is simply returned.
        Specified by:
        getButtonIndex in class AbstractRadioButtonHandler<Integer>
        Parameters:
        value - the data value
        Returns:
        the index of the corresponding radio button
      • getDataForButton

        protected Integer getDataForButton​(int idx)
        Returns the data value that corresponds to the radio button with the given index. Again because there is a 1:1 mapping between radio button index and data value the index can be directly returned as value.
        Specified by:
        getDataForButton in class AbstractRadioButtonHandler<Integer>
        Parameters:
        idx - the index of the selected radio button
        Returns:
        the corresponding data value