I'm creating a List of javax.faces.model.SelectItem
(in a bean) for use with a h:selectManyCheckbox
but I cannot figure out how to make a SelectItem
selected.
How to do this? Must be possible, right?...
public List<SelectItem> getPlayerList(String teamName) {
List<SelectItem> list = new ArrayList<SelectItem>();
TeamPage team = (TeamPage) pm.findByName(teamName);
List<PlayerPage> players = pm.findAllPlayerPages();
for (PlayerPage player : players) {
boolean isMember = false;
if (team.getPlayerPages().contains(player)) {
isMember = true;
}
SelectItem item;
if (isMember) {
// TODO: Make SelectItem selected???
item = null;
} else {
item = new SelectItem(player.getId(), createListItemLabel(player), "", false, false);
}
list.add(item);
}
return list;
}
Assume we have this JSF code:
<h:selectManyCheckbox value="#{bean.selectedValues}">
<f:selectItems value="#{bean.playerList}"/>
</h:selectManyCheckbox>
then the selected values (i.e. the checked checkboxes) are stored in the bean.selectedValues property.
Thus, in your Java code, you must handle the selectValues by putting the correct ID in the selectedValues property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With