July 27th, 2011
9:05 am
f:selectItem error – java.lang.String cannot be cast to javax.faces.model.SelectItem

Posted under JSF
Tags , ,

I received this error when using <f: selectItem> on a prototype of a page:-

java.lang.ClassCastException: java.lang.String cannot be cast to javax.faces.model.SelectItem

It turns out that the error was trivial, but easy to miss at first glance.

My initial code was as follows:-

<f:selectItem value=”1″ itemLabel=”&lt;default&gt;”/>

The mistake was to use the value attribute instead of the itemValue  attribute. The following is the corrected code:-

<f:selectItem itemValue=”1″ itemLabel=”&lt;default&gt;”/>

 This solves the problem.

No Comments »

Trackback URI | Comments RSS

Leave a Reply

You must be logged in to post a comment.