Skip to content

RADButtonList

Steve Hannah edited this page Jul 8, 2021 · 2 revisions

ButtonListPropertyView

<radButtonList>javadoc

Synopsis

A binding wrapper for ButtonList subclasses such as CheckBoxList, RadioButtonList, and SwitchList. This allows us to bind the selections in a ButtonList with property in the ViewModel.

Usage

Unlike other <rad*> components, this component must include the actual ButtonList being bound as a child tag. E.g:

A radButtonList binding the selections of its child checkBoxList to the favColors property of the view model.
<!-- define a favColors property on the view model of type
    List -->
<define-tag name="favColors" type="java.util.List" initialValue="new"/>

<!-- Create a checkbox list to select entries in the favColors prop -->
<radButtonList tag="favColors">
    <checkBoxList multiSelectModel="csv:Red, Green, Blue"/>
</radButtonList>
Tip
The above example uses the csv: prefix for the multiSelectModel property. This will cause the values to be interpreted as CSV (comma-separated-value strings), and will convert it into a ListModel. The csv: prefix can be used in attributes expecting String[] or ListModel.

Attributes

tag

References the Tag for the property of the view model that it should be bound to.

View Model

The bound property needs to be compatible with the row-type of the list model of the ButtonList.

For MultipleSelectionListModels (e.g. CheckBoxList and SwitchList models), the bound property should be able to hold multiple values. E.g. it needs to be a Collection or EntityList type.

For single selection ListModels (e.g. RadioButtonList), then bound property should match the row-type of the button list model. E.g. If the ButtonList model includes Strings, then the bound property should be of type String. If the ButtonList model includes Entity objects, then the bound property should be of type Entity.

Examples

CheckBoxList

Tip
See CheckBoxList for more examples using <checkBoxList>.
<define-tag name="favColors" type="java.util.List" initialValue="new"/>

<!-- A checkboxlist bound to a list property -->
<radButtonList tag="favColors">
    <checkBoxList multiSelectModel="csv:Red, Green, Blue"/>
</radButtonList>
CheckBoxList

CheckBoxList With Entities

<!-- To create a ListModel with entities we construct an EntityList
    in a <script> tag.  This is bad form - just used here for clarity.
-->

<!-- Define a variable to hold the profiles EntityList which we
    will use for the ListModel -->
<var name="profiles" type="EntityList"/>
<script>
    profiles = new EntityList();
    for (String name : new String[]{"Steve", "Shai", "Chen", "Lois", "Clark", "Rogue"}) {
        UserProfile profile = new UserProfileImpl();
        profile.setName(name);
        profiles.add(profile);
    }
</script>

<!-- Define a view model property to old the selected favourite profiles
    -->
<define-tag name="favProfiles" type="EntityList" initialValue="new"/>
<radButtonList tag="favProfiles">
    <!-- CheckBoxList with the profiles as its listmodel -->
    <checkBoxList model="profiles.toMultipleSelectionListModel()"/>
</radButtonList>
CheckBoxList2

SwitchList

<define-tag name="favColors" type="java.util.List" initialValue="new"/>

<!-- A switchlist bound to a list property -->
<radButtonList tag="favColors">
    <switchList multiSelectModel="csv:Red, Green, Blue"/>
</radButtonList>
SwitchList

RadioButtonList

<define-tag name="favCartoonCharacter"/>
<radButtonList tag="favCartoonCharacter">
    <radioButtonList model="csv:Wolverine, Optimus Prime, Bugs Bunny"/>
</radButtonList>
RadioButtonList

SwitchList with BoxLayout.y()

<define-tag name="favColors" type="java.util.List" initialValue="new"/>

<radButtonList tag="favColors">
    <switchList multiSelectModel="csv:Red, Green, Blue" layout="BoxLayout.y()"/>
</radButtonList>
SwitchList BoxLayout y
Clone this wiki locally