• Post Reply Bookmark Topic Watch Topic
  • New Topic

Trouble with JSF selectOneMenu  RSS feed

 
Len Smith
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java Noob here.

I have been trying for hours to get the selected item for my selectOneMenu to work correctly. I have looked through this forum trying to find information on it myself and have tried everything. Please help! Below is my JSF for the selectOneMenu.


Here is my bean.


The values of the list show up as expected in the Drop Down. However when I click the commandButton on my page, the selected value that is passed in is always null.

What am I missing? Do I need a converter? I thought with all the tags I have on the selectItems tag that everything should work OK.

Thanks in advance for the help.



 
Ilari Moilanen
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that if you want to put the object itself as a value you need access of the html element (select) itself. So you need to have the element binded to the element in the backing bean as well with the structure you want. You can not send objects with normal html post so you need to put for example some identifying id to itemValue attribute and not the object itself if you do not want to use binding. Someone with more experince on the binding can correct me if I am wrong. I myself have only used the approach where the itemValue is something you can send with html post (i.e. the (database or something similar) id of the object).
 
Tim Holloway
Bartender
Posts: 18715
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your "selectitems" element is even remotely valid, some options have been added that weren't in the original spec.

However, legal or not, you have some serious confusions between singular and plurals here (var="group" vs. getGroups(), "selectItems" vs "selectItem").

And, just for the record: a backing bean is NOT a Controller. It's a Model.
 
Ilari Moilanen
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:If your "selectitems" element is even remotely valid, some options have been added that weren't in the original spec.

However, legal or not, you have some serious confusions between singular and plurals here (var="group" vs. getGroups(), "selectItems" vs "selectItem").

I do not follow. Could you please me more specific? For example I have this code in my own application that IS valid and works as intended. And the only difference is the one I told in my above post.
 
Tim Holloway
Bartender
Posts: 18715
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see a "setSelected" method.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!