• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Problem to populate a selectOneListbox from a Java-Bean

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 21
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks

the wrong references was the Problem
 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you provide code and log for the same??
 
I do some of my very best work in water. Like this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic