发生错误:无法将java.util.HashMap强制转换为javax.faces.model.SelectItem

时间:2013-11-20 10:47:54

标签: primefaces

我正在尝试实施AJAX - 从http://www.primefaces.org/showcase/ui/pprSelect.jsf

中选择组件

但是我收到以下错误 发生错误:java.util.HashMap无法强制转换为javax.faces.model.SelectItem

这是我的堆栈树

java.lang.ClassCastException: java.util.HashMap cannot be cast to javax.faces.model.SelectItem
at org.primefaces.renderkit.InputRenderer.getSelectItems(InputRenderer.java:47)
at org.primefaces.component.selectonemenu.SelectOneMenuRenderer.encodeMarkup(SelectOneMenuRenderer.java:71)
at org.primefaces.component.selectonemenu.SelectOneMenuRenderer.encodeEnd(SelectOneMenuRenderer.java:65)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:924)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312)
at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)
at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:894)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at org.primefaces.component.tabview.TabViewRenderer.encodeTabContent(TabViewRenderer.java:279)
at org.primefaces.component.tabview.TabViewRenderer.encodeContents(TabViewRenderer.java:237)
at org.primefaces.component.tabview.TabViewRenderer.encodeMarkup(TabViewRenderer.java:127)
at org.primefaces.component.tabview.TabViewRenderer.encodeEnd(TabViewRenderer.java:71)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:924)
at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:63)
at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:47)
at org.primefaces.component.panel.PanelRenderer.encodeContent(PanelRenderer.java:202)
at org.primefaces.component.panel.PanelRenderer.encodeMarkup(PanelRenderer.java:119)
at org.primefaces.component.panel.PanelRenderer.encodeEnd(PanelRenderer.java:56)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:924)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:894)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:443)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:724)

这是jsf页面的相关部分

 <h:outputText id= "diagnosisType" value="Diagnosis Type" />  
                            <p:selectOneMenu value="#{patient.diagnosisType}">  
                                <f:selectItem itemLabel="" itemValue="" />
                                <f:selectItem value ="#{patient.diagnosisType_p}" />
                                 </p:selectOneMenu>  

和托管bean

String diagnosisType;

private Map<String,String> diagnosisType_p = new HashMap<String, String>(); 

public Patient() {
    diagnosisType_p.put("Provisional Diagnosis", "Provisional Diagnosis");  
    diagnosisType_p.put("Final Diagnosis", "Final Diagnosis"); 
}

public Map<String, String> getDiagnosisType_p() {
    return diagnosisType_p;
}

public void setDiagnosisType_p(Map<String, String> diagnosisType_p) {
    this.diagnosisType_p = diagnosisType_p;
}

我在netbeans7.3.1上使用了primefaces 3.5

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:0)

使用f:selectItems

<h:outputText id= "diagnosisType" value="Diagnosis Type" />  
<p:selectOneMenu value="#{patient.diagnosisType}">  
   <f:selectItem itemLabel="" itemValue="" />
   <f:selectItems value ="#{patient.diagnosisType_p}" />
</p:selectOneMenu>