Problems retrieving more selected items from a CheckBoxGroup
Hello!
I've one big problem I can't work out: I'm trying to use a CheckBoxGroup to select more than one value from a list of four. I need the changes to be auto-submitted. The problem is that after the data is submitted to the server and comes back to the browser, only one item is selected, namely the previously selected one lower in the page. Debugging I noticed that calling getSelected() on this checkbox group always gives an array of length 1! The same happens when I don't auto-submit the values.
Here is what I've done:
In SessionBean1:
....
private Option[] availabilitiesOptions;
private String[] availabilitiesSelected;
public SessionBean1(){
.....
availabilitiesOptions=new Option[]{// Values are taken from byte constants
new Option(new Byte(AvailabilityType.UNLICENSED).toString(),
"Contacts without licenses"),
new Option(new Byte(AvailabilityType.LICENSED).toString(),
"Contacts with licenses"),
new Option(new Byte(AvailabilityType.PARTNER).toString(),
"Partners"),
new Option(new Byte(AvailabilityType.ADMIN).toString(),
"Administrators")
};
availabilitiesSelected=new String[]{};
}
public Option[] getAvailabilitiesOptions(){
return this.availabilitiesOptions;
}
publicvoid setAvailabilitiesOptions(Option[] availabilitiesOptions){
this.availabilitiesOptions = availabilitiesOptions;
}
public String[] getAvailabilitiesSelected(){
return this.availabilitiesSelected;
}
publicvoid setAvailabilitiesSelected(String[] availabilitiesSelected){
this.availabilitiesSelected = availabilitiesSelected;
}
In 'Design' of the web page:
I added a CheckBoxGroup, set it to 'auto-submit on change' and set immediate to true;
I bound the data to #{SessionBean1.availabilitiesOptions} choosing from the 'Bind to an object' panel. I set the 'selected' property to #{SessionBean1.availabilitiesSelected} from the Properties panel
I then double-clicked the checkBoxGroup to add the following code:
publicvoid availabilityCheckBoxes_processValueChange(ValueChangeEvent event){
String[] selection=(String[])availabilityCheckBoxes.getSelected();
.....
// The following line is to avoid validation of other required components
FacesContext.getCurrentInstance().renderResponse();
}
Debugging, selection
has always only one item!!
I think this is all I've done concerning this issue.
I hope I'm doing something wrong and it's not an IDE bug, but please help me find out where's the problem!!
Thanks
Davide
PS: I'm using version 060120 on Windows XP

