我想在数组中设置值但收到 Classcastexception ..
代码示例:page.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Really simple CRUD</title>
</h:head>
<h:body>
<h:form id="form">
<p:growl autoUpdate="true" showDetail="true"/>
<h:selectOneMenu converter="javax.faces.Integer" value="#{adminMBean.a[0]}">
<f:selectItem itemLabel="1" itemValue="1"/>
<f:selectItem itemLabel="2" itemValue="2"/>
</h:selectOneMenu>
<h:commandButton value="ok" action="#{adminMBean.ok()}"/>
<h:outputText value="sa:#{adminMBean.a[0]}"/>
</h:form>
</h:body>
@ManagedBean(name = "adminMBean")
@RequestScoped
public class AdminMBean {
int[] a=new int[1];
public AdminMBean(){}
public int[] getA() {
return a;
}
public void setA(int[] a) {
this.a = a;
}
}
如何使用 selectonemenu 将值设置为数组?