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


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSF
Reply 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: 14480
    
    7

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: 189

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: 189

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)


 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: combobox options
 
Similar Threads
Unsure where to ask this question....
Servlet to servlet
Hibernate one-to-many inner join?
Taglib question more info...
java.lang.Reflection throwing error when using (String)field.get(new String());