Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

selectOneMenu & Conversion Error setting value '2' for 'null Converter'  RSS feed

 
wadha alketbi
Ranch Hand
Posts: 56
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I want to select a record from the database and add it in the list, my method dose not work with me. also if there is any link that will help me to create a selectOneMenu by using this method and call it in my back bean. finally i want to know if this error is related to the selectOneMenu, the error is(Conversion Error setting value '2' for 'null Converter').

Select method:



thank you
 
Tim Holloway
Bartender
Posts: 18709
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JSF selectOneMenu control is its counterpart to the HTML <SELECT> and <OPTION> tags. The OPTION tag has an attribute (value) and a body (label), so the SelectOneMenu must likewise allow for those 2 items.

Because of that, a simple List or array of string values is not a suitable 'value=' property model for selectOneMenu.

JSF defines a prototype model class to hold OPTION definitions. It is the SelectItem class and it can be instantiated with a label and value or just a label - in which case the SelectItem instance will use the label also as its value.

Your conversion is failing because of this simple fact: you are attempting to return a List of Strings where you should be returning a List of SelectItem objects.

There is also an additional problem, though. JSF "get" methods can be called 5 or 6 times for a single page operation, which means 5 or 6 repeats of fetch data from the backing database. That is very inefficient and can slow down your page rendering. It also has the potential to become corrupt, if the list of items that are pulled changes between one call of your "get" method and the next on the same page request.

A safer and more reliable way of setting up the SelectItem list would be to create the list of SelectItem objects from the database before the getAllStatus() method is first called, save that list as an internal backing bean property and have getAllStatus() return it.
 
Uwe Lindenberg
Ranch Hand
Posts: 44
2
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,

perhaps we can use f:selectItems value="#{beanHandler.theData" var="oneData" itemLabel="#{oneData.information1}" itemValue="#{oneData}" instead of selectItem (without s) ?

Of course theData should bei initialized only one time.

Best regards,

Uwe
 
Tim Holloway
Bartender
Posts: 18709
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that you can use  the itemLabel and itemValue properties on "f:selectItems" where the itemLabel and itemValue properties are 2 sequential collections (for example, a List of labels paired with a List of values).

However, since a JSF backing bean is first and foremost a JSF UI Model object anyway, I find it easier to simply build a list of SelectItem objects in the backing bean code when I query the database and return the finished list as a simple selectItems value.

I don't see any particular virtue in forcing JSF to do the same thing using VDL tags and it does add the risk that your label and item lists could end up out of sync, which would cause things to explode at run time,

I hate run-time explosions. They lie in wait until the moment that they can cause me the most embarrassment before exploding.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!