Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selectonemenu with the error java.lang.String cannot be cast to javax.faces.model.SelectItem

Tags:

java

jsf

I want to fill a selectonemenu but always I have this error :

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

this is the code:

public class ToolsJIRA implements Serializable{

private String myChoicePeriod;

 //getters and setters
}

JSF:

  <h:selectOneMenu value="#{ToolsJIRA.myChoicePeriod}">
                   <f:selectItem itemValue="Month" value="Month"/>
                   <f:selectItem itemValue="Week" value="Week"/>
                   <f:selectItem itemValue="Year" value="Year"/>
  </h:selectOneMenu> 

I have found that I should write a converter but I don't Know why? beacause I have seen some example work without a converter??

thank you

like image 215
rym Avatar asked Jun 27 '11 09:06

rym


1 Answers

Try this code in in your webpage

<h:selectOneMenu value="#{checkBoxBean.myChoicePeriod}">
                <f:selectItem itemValue="Month" />
                <f:selectItem itemValue="Week" />
                <f:selectItem itemValue="Year" />
             </h:selectOneMenu>

Do not use value attribute its inteded for different purpose

like image 80
Maddy Avatar answered Sep 19 '22 17:09

Maddy