• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

h:selectOneMenu problem evaluating to empty String

 
Kinildson Persegueiro
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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!
 
Brajendra Mathema
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • 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 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
Posts: 12
  • Mark post as helpful
  • send pies
  • 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>

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

Suggestions?
Thanks again!
 
Rohit Boorugu
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic