RADButtonList - shannah/CodeRAD GitHub Wiki
<radButtonList>
• javadoc
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.
Unlike other <rad*>
components, this component must include the actual ButtonList being bound as a child tag. E.g:
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 .
|
- tag
-
References the Tag for the property of the view model that it should be bound to.
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
.
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](https://github.com/shannah/CodeRAD/wiki/images/CheckBoxList.png)
<!-- 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](https://github.com/shannah/CodeRAD/wiki/images/CheckBoxList2.png)
<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](https://github.com/shannah/CodeRAD/wiki/images/SwitchList.png)
<define-tag name="favCartoonCharacter"/>
<radButtonList tag="favCartoonCharacter">
<radioButtonList model="csv:Wolverine, Optimus Prime, Bugs Bunny"/>
</radButtonList>
![RadioButtonList](https://github.com/shannah/CodeRAD/wiki/images/RadioButtonList.png)