aspose file tools*
The moose likes JSF and the fly likes combobox options Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "combobox options" Watch "combobox options" New topic
Author

combobox options

anna popova
Greenhorn

Joined: May 05, 2011
Posts: 6
how can i put my categories values into drop down list ?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15662
    
  15

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
anna popova
Greenhorn

Joined: May 05, 2011
Posts: 6
thanks for reply.
this is the part of my code

what's wrong?
Guy deLyonesse
Ranch Hand

Joined: Apr 12, 2011
Posts: 199

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

Joined: May 05, 2011
Posts: 6
even if the type of "itm" is String?
Guy deLyonesse
Ranch Hand

Joined: Apr 12, 2011
Posts: 199

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)


 
Consider Paul's rocket mass heater.
 
subject: combobox options
 
Similar Threads
Unsure where to ask this question....
Hibernate one-to-many inner join?
java.lang.Reflection throwing error when using (String)field.get(new String());
Servlet to servlet
Taglib question more info...