• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

h:selectOneMenu problem evaluating to empty String

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it string value and it is in jsf page we get it as empty string ie:""

you can check it out be using h:outputtext

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
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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>

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

Suggestions?
Thanks again!
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic