my dog learned polymorphism*
The moose likes JSF and the fly likes h:selectOneMenu problem evaluating to empty String  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "h:selectOneMenu problem evaluating to empty String  " Watch "h:selectOneMenu problem evaluating to empty String  " New topic
Author

h:selectOneMenu problem evaluating to empty String

Kinildson Persegueiro
Greenhorn

Joined: Aug 04, 2008
Posts: 12

Hi there,

I have a selectOneMenu like this...

<h:selectOneMenu id="combo" value="${myBackingBean.myString}" >
<f:selectItem itemValue="A" itemLabel="Ok, there's some text... " />
<f:selectItem itemValue="null" itemLabel="Never is Selected" />
</h:selectOneMenu>

Sometimes myBackingBean.myString evaluates to an empty String, I mean it has a null value.
But when this happens, the correct option, that would be itemValue="null" itemLabel="Never is Selected" isn't selected by default.
In fact, I don't know why, the oder option is selected instead - "Ok, there's some text... "

I've found this on the web ...

discussion, same problem

It's the same case, then I tried these changes...

<f:selectItem itemLabel="Never is selected" />

<f:selectItem itemValue="${null}" itemLabel="Never is selected" />

<f:selectItem itemValue="null" itemLabel="Never is selected" />

Neither of them worked...
Suggestions please? Thanks!
Brajendra Mathema
Ranch Hand

Joined: Jun 02, 2009
Posts: 39
it string value and it is in jsf page we get it as empty string ie:""

you can check it out be using hutputtext

so null value from the select box will never be selected if you provide empty string value it will be selected .

<h:selectOneMenu value="#{test.sel}" id="combo">
<f:selectItem itemValue="" itemLabel="Never selected"/>
<f:selectItem itemValue="one" itemLabel="selected one"/>
</h:selectOneMenu>

if sel has null value then Nerver selected would be default selected
if sel has value "one" then selected one would be defauld selected

brajend
Kinildson Persegueiro
Greenhorn

Joined: Aug 04, 2008
Posts: 12

Ok, I've done some changes...

<h:selectOneMenu id="combo" value="${myBackingBean.myString}" >
<f:selectItem itemValue="A" itemLabel="Ok, there's some text... " /> <!-- error - this is chosen by default! -->
<f:selectItem itemValue="" itemLabel="Never is Selected" />
</h:selectOneMenu>

<hutputText value="${myBackingBean.myString}"/> <!-- evaluates to nothing, ok -->
<hutputText value="${myBackingBean.myString == null}"/> <!-- evaluates to true -->

Suggestions?
Thanks again!
Rohit Boorugu
Greenhorn

Joined: Oct 06, 2009
Posts: 14
hey kin, I donno if you have done these but just telling you. first thing is you need to have this selectoneitem enclosed in a form so that data is sent to the backing bean. the other thing is with the code you have the data is never sent to backing bean as you dont have an event.

try it in this format..it might help
<form>
<h:selectOneMenu id="combo" value="${myBackingBean.myString}" >
<f:selectItem itemValue="A" itemLabel="Ok, there's some text... " />
<f:selectItem itemValue="null" itemLabel="Never is Selected" />
<a4j:support event="onclick" rerender="combo">
</h:selectOneMenu>
</form>

hope this helps. Let me know what happened
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: h:selectOneMenu problem evaluating to empty String
 
Similar Threads
Issue with my webApp
Probem in javascript in a JSF when implementing tiles in it
can anybody help ??
JSF Dropdown list
How to create Hyperlink for SelectItem