tags:

views:

2538

answers:

1

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.

Does anyone know 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;
}
+3  A: 

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.

romaintaz
thanks for the quick response/answer!
mafro