Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

JSF:SelectOneMenu validating

  Asked By: Adelisa    Date: Jul 09    Category: Java    Views: 2549

I have a dropdownList and its binded to a Long value in my managed Bean,

But I am getting "Value is not valid" error
here is my code

<h:selectOneMenu id="testSelectOneMenu" value="#{myBean.LongParameter}" >
<f:selectItem id="item1" itemLabel="News" itemValue="1" />
<f:selectItem id="item2" itemLabel="Sports" itemValue="2" />
<f:converter converterId="javax.faces.Long" />

interesting things is if i change it to
<h:inputText id="testInputText" value="#{myBean.LongParameter}" >
<f:converter converterId="javax.faces.Long" />
</h:inputText >

it works fine..

Can anybody explain this behavior?



3 Answers Found

Answer #1    Answered By: Norman Ray     Answered On: Jul 09

how about not to put that converter?

Answer #2    Answered By: Leon Evans     Answered On: Jul 09

you have several approach to solve this problem :
1- use tomahawk taglib converter to solve your problem.
2- use MyFaces or RI converter to do this.
3- develop custom converter to solve your problem.
But don't forget this, easiest of all is bind your value to string field in your Bean and
when you wanna use it, convert it to long.

Answer #3    Answered By: Garai Chalthoum     Answered On: Jul 09

I don't know what you have been expecting,
but the way you have used <f:selectItem ...> it returns String (not Long)

and a note about JSF standards components:
they are very simple minimal components just to show how JSF should be.
for real world projects you have to choose a 3'rd party component set either open source or commercial.

Didn't find what you were looking for? Find more on JSF:SelectOneMenu validating Or get search suggestion and latest updates.