Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Dynamically add items to listbox (JSF)

843844Jul 22 2008 — edited Jul 22 2008
Hi,
I am using netbeans 6.1 to develop a JSF web application where i need to populate a listbox with dynamic values from a DB. (Mysql)...
am trying to use selectOneListbox ui and feed it dynamic values.
<h:selectOneListbox binding="#{Testing_page.chpt_detail_lst}" id="chpt_detail_lst"
                            onchange="common_timeoutSubmitForm(this.form, 'chpt_detail_lst');" size="5"
                            style="height: 192px; left: 408px; top: 144px; position: absolute; width: 168px" valueChangeListener="#{Testing_page.chpt_detail_lst_processValueChange}">
                            <f:selectItems id="chpt_list" value="#{Testing_page.chpt_detail_lstDefaultItems}"/>
                        </h:selectOneListbox
I am able to set static values to the listbox using 'SelectItem[]" but when i try to feed the listbox dynamic values using selectitem in the getter function it doesn't work.
{code}private List chpt_detail_lstDefaultItems = { new SelectItem(new Integer(1), "Atkljkkjkjklom"),
new SelectItem(new Integer(2), "Cathod Ray"),
new SelectItem(new Integer(3), "English"),
new SelectItem(new Integer(4), "Ripple tank")
};{code}
I tried to replace SelectItem with List but that gave me a whole bunch of other errors.

basically please guide me how to simply change/edit/delete items from a listbox on runtime.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 19 2008
Added on Jul 22 2008
3 comments
938 views