File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes Cannot set a value in selectOneMenu Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Cannot set a value in selectOneMenu " Watch "Cannot set a value in selectOneMenu " New topic

Cannot set a value in selectOneMenu

Paul Smiley
Ranch Hand

Joined: Jun 02, 2000
Posts: 244
Does anyone have a working snippet they can share on this? I've been hacking on this for some time, but no luck. Here's what I want to do.

I have a selectOneMenu that I wish to populate from a database. I get the values fine. However, I can't seem to set the selected item in that dropdown. It always defaults to the top one in the list. I have tried method binding, value binding and the whole 9 yards, but I can't seem to set this thing before it renders.

A related problem - when I select a value in this combo box, it changes to display the correct one. I submit the form and it goes away. It seems like something is saving the prior state and resetting it. I am not doing a save state myself.

Here's the hitch. I'm not using a simple select item - I have to carry a DB id with each select item, so I had to make a IdSelectItem subclass of SelectItem. Then I had to write a converter to display it (why it couldn't just recognize this was a subclass of SelectItem and render as such I'll never know).

If anyone has a clue on where I should go from here, I'd be grateful!

Daniel Prene
Ranch Hand

Joined: Jul 15, 2005
Posts: 241
Could you please post your current code?
Paul Smiley
Ranch Hand

Joined: Jun 02, 2000
Posts: 244
Can't post the code - I work for BTSO (OK, those of you with kids - ever watch Jimmy Neutron with your kids? You'll know what I mean.)

My problem wasn't with the JSF code at all, it was a Hibernate mapping issue on the back end - submittedValues didn't match what was in the dropdown list.

I'm happy now...

BTW, BTSO means "Big Top Secret Organization".
I agree. Here's the link:
subject: Cannot set a value in selectOneMenu
It's not a secret anymore!