Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SelectOneMenu Value not getting set in bean

 
Omkar Anandache
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am using <h:selectOneMenu> in my code for a dropdon with <f:selectItems>

The problem is strBeanVal bean variable is getting set to blank.

The Value seen in view source html is as highlighted in blue-

<option value="2000000000050019@CENTER FOR MEDICINE-0010006770>2502 B E EMPIRE ST*BLOOMINGTON&Illinois%61704<$ManageSoldTo">CENTER FOR MEDICINE-0010001110</option>


Below is my code


This works fine with --<option value="2000000000050019">CENTER FOR MEDICINE-0010001110</option>

Is the value getting set to blank because of special characters or too many characters in the value??

Any help is appreciated.

Thanks in advance
 
K. Tsang
Bartender
Posts: 3524
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You missing the "#" is the <h:selectOneMenu> value attribute.

And welcome to the Ranch.
 
Omkar Anandache
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.

Its a typo error but my actual code has it.
 
Omkar Anandache
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have edited the post
 
K. Tsang
Bartender
Posts: 3524
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a submit button or something like ajax? Don't expect the value gets assigned magically upon selecting.
 
Omkar Anandache
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a form submit.

As i have mentioned in my post that it works finne with <option value="2000000000050019">CENTER FOR MEDICINE-0010001110</option>
 
K. Tsang
Bartender
Posts: 3524
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code looks fine to me. When the form submits, you should get the value 2000000000050019 in the variable strBeanVal of the bean. Isn't this what you expected?
 
Tim Holloway
Saloon Keeper
Posts: 18304
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could end up with a blank value if the backing bean's SelectItem list changes and the selection value is no longer in the list. Although that can also lead to validation errors.

A list mismatch can occur for several reasons. One of them would be if you tried to use Request scope on the backing bean. Request scope in JSF isn't as usable as it is in straight J2EE.
 
K. Tsang
Bartender
Posts: 3524
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah yes Tim, the bean's scope can be an issue. I usually use view scope. If must session scope. Hardly request scope.

Omkar, what scope is your managed bean?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic