aspose file tools*
The moose likes JSF and the fly likes Problem to populate a selectOneListbox from a Java-Bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Problem to populate a selectOneListbox from a Java-Bean" Watch "Problem to populate a selectOneListbox from a Java-Bean" New topic
Author

Problem to populate a selectOneListbox from a Java-Bean

Martin Mikolajek
Greenhorn

Joined: Jan 10, 2007
Posts: 14
Hello,
i can't set the values for the ListBox
here is my coding:

public List getDrinks() {
drinks = new ArrayList();
drinks.add(new SelectItem(new Integer(1),"Kaffee"));
drinks.add(new SelectItem(new Integer(2),"Tee",""));
drinks.add(new SelectItem(new Integer(3),"Milch",""));
drinks.add(new SelectItem(new Integer(4),"Kakao",""));
return drinks;
}
and this is the JSF definition
<h:selectOneListbox styleClass="selectOneListbox" id="drink" size = "1" value="#{pc_Welcome.mo_User.drink}">
<f:selectItems value="#{selectitems.pc_Welcome.mo_User.drinks.drinks.toArray}" />
</h:selectOneListbox>

and the Output of the Box looks:

javax.faces.model.SelectItem@xxxxxxxx
javax.faces.model.SelectItem@xxxxxxxx
javax.faces.model.SelectItem@xxxxxxxx
javax.faces.model.SelectItem@xxxxxxxx
xxxxxxx is the Reference to an Object (i think)

can anybody help me and tell me what i am doing wrong ???

Thanks
Franz van Betteraey
Greenhorn

Joined: Jun 20, 2007
Posts: 18
Hi,

better predefine the List in the bean-properties in faces-config.xml like:



and than code the List in Java like this (you also need of course a property "drink" for the selected value.



and in jsp



You don't need to create SelectItem-Objects in the List and also it seems that you are doing to much converting and wrong referencing (.drinks.drinks.toArray)in your code.

Hope this helps.

Regards
Klaus
[ July 23, 2007: Message edited by: Klaus Classen ]
Martin Mikolajek
Greenhorn

Joined: Jan 10, 2007
Posts: 14
Thanks

the wrong references was the Problem
siva prakash
Ranch Hand

Joined: Aug 24, 2004
Posts: 80
Hi,

I am displaying dynamic data at SelectOneListBox, hence i can't predefine its values faces-config. so i am creating array list of SelectItem objects with constructor taking two string objects. and binded at jsp. but still i am not getting values dispalyed.

Can any one help on this , its very urgent, iam breaking my head on this from couple of days.



Thanks,
Prakash
Tushar Kherde
Ranch Hand

Joined: Apr 28, 2006
Posts: 56
Can you provide code and log for the same??


Tushar
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem to populate a selectOneListbox from a Java-Bean