Java. With error Selectonemenu of lang. string cannot be cast to javax. String faces. model. SelectItem

I want to fill in a selectonemenu, but there is always 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 found that I should write a converter, but I don't know why? Because I've seen some sample work without a converter?

thank you

Solution

Try this code on your web page

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

Do not use the value of its attribute for different purposes

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>