Hi Guys and gals,
I have been banging my head against this wall for a couple days and am coming up to the stage where I just put in an ugly work around, but I would rather solve it and learn something, so any help would be very much appreciated.
I need to dynamically populate a h:selectManyListbox, I am using the f:selectItems linked to an array list of selectItem 's on my backing bean, as follows:
<h:selectManyListbox styleClass="selectManyListbox" id="avaliableProgs"> <f:selectItems value="#{pc_EditProgrammeMatrix.availableProgrammes}"/> </h:selectManyListbox>
(cutdown) Page code to populate the Select Items:
public ArrayList<SelectItem> getAvailableProgrammes(){ ProgrammeLite currentProgrammeLite; Iterator avilableIterator = getProgrammeHandler().getAllProgrammeLites().iterator(); this.availableProgrammes.clear(); while(avilableIterator.hasNext()){ currentProgrammeLite = (ProgrammeLite) avilableIterator.next(); this.availableProgrammes.add(new SelectItem((Integer) currentProgrammeLite.getID(), currentProgrammeLite.getTitle())); } return this.availableProgrammes; }
This populates the SelectItems, allowing me to iterate through them, printing their value and label to the console. When returned to the JSF, the selectManyListbox is empty.
To test this, I manually populated the SelectItems array:
public ArrayList<SelectItem> getAvailableProgrammes(){ this.availableProgrammes.add(new SelectItem((Integer) 1, "Hello"); this.availableProgrammes.add(new SelectItem((Integer) 2, "World"); return this.availableProgrammes; }
This works correctly and displays the SelectItems.
I think this may have something to do with the JSF life cycle, but I am unable find a solution.
Any suggestions, help, or appropriate work around would be very much appreciated. Let me know if you need more info, etc.