| 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 h utputtext
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>
<h utputText value="${myBackingBean.myString}"/> <!-- evaluates to nothing, ok -->
<h utputText 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
|
 |
 |
|
|
subject: h:selectOneMenu problem evaluating to empty String
|
|
|