• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

combobox options

 
anna popova
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can i put my categories values into drop down list ?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18212
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to add a property to your backing bean that can read (get) a SelectItem collection (List or array).

There are 2 parts to HTML <OPTION> elements - the value and the label. So it requires a special object to supply both items, even in cases where the label and value are the same. The JSF SelectItem serves that function.

Basically, just iterate your String array and create a SelectItem for each string (there's a single-element constructor that can be used when the label and value are the same string).

For best results, create the SelectItem list when you first need it and cache it in a member variable in the backing bean. That saves overhead.
 
anna popova
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for reply.
this is the part of my code

what's wrong?
 
Guy deLyonesse
Ranch Hand
Posts: 200
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anna popova wrote:thanks for reply.
this is the part of my code

what's wrong?


You need to specify the member within the "itm" objects.

Your code should look something like this:

 
anna popova
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
even if the type of "itm" is String?
 
Guy deLyonesse
Ranch Hand
Posts: 200
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ArrayList should contain SelectItem objects, not Strings.



Then the code in your view would be something like this:



(I know that's different from what I said earlier... please disregard. I was thinking of a different control.)

The value of the SelectOneMenu is a String, which is the currently selected list item value. The items themselves are passed as an ArrayList of SelectItems.

(This is done in JSF 1.2)


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic