我有一些JSF麻煩,使用h:selectOneMenu和後端列表豆: 我的XHTML文件看起來是這樣的:JSF h:selectOneMenu麻煩:java.lang.IllegalArgumentException無法將類java.lang.String的「字符串」轉換爲接口java.util.List
<f:view>
<h:form id="serverOptions">
<h:selectOneMenu id="preset" value="#{overview.pdfPresets}" >
<f:selectItems value="#{overview.pdfPresets}" />
</h:selectOneMenu>
<h:commandButton action="submit" value="Submit" />
</h:form>
</f:view>
,其中相應的管理豆看起來是這樣的:
private List<String> pdfPresets;
private String pdfPreset;
/**
* Returns a list of pdfPresets
* @return a List<String> of pdf preset names
*/
public final List<String> getPdfPresets() {
return pdfPresets;
}
/**
* Sets the name of the selected pdfPreset
* (trying to overload setPdfPresets here)
* @param presetName
* @see setPdfPreset
*/
public final void setPdfPresets(String presetName) {
// write preset name somehwere else
this.presetName = presetName;
}
/**
* Sets the pdfPresets
* @param list
*/
public final void setPdfPresets(List<String> list) {
pdfPresets = list;
}
在我的瀏覽器提交表單出現的問題,完整的錯誤堆棧看起來像這個:
EVERE: An exception occurred
javax.faces.component.UpdateModelException: java.lang.IllegalArgumentException: Cannot convert screen_druckbogen of type class java.lang.String to interface java.util.List
at javax.faces.component.UIInput.updateModel(UIInput.java:398)
at javax.faces.component.UIInput.processUpdates(UIInput.java:299)
at javax.faces.component.UIForm.processUpdates(UIForm.java:187)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1258)
at javax.faces.component.UIViewRoot._processUpdatesDefault(UIViewRoot.java:1317)
at javax.faces.component.UIViewRoot.access$600(UIViewRoot.java:75)
at javax.faces.component.UIViewRoot$UpdateModelPhaseProcessor.process(UIViewRoot.java:1419)
at javax.faces.component.UIViewRoot._process(UIViewRoot.java:1278)
at javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java:761)
at org.apache.myfaces.lifecycle.UpdateModelValuesExecutor.execute(UpdateModelValuesExecutor.java:34)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:171)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:440)
at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:943)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: java.lang.IllegalArgumentException: Cannot convert screen_druckbogen of type class java.lang.String to interface java.util.List
at com.sun.el.lang.ELSupport.coerceToType(ELSupport.java:397)
at com.sun.el.parser.AstValue.setValue(AstValue.java:164)
at com.sun.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:273)
at org.apache.myfaces.view.facelets.el.TagValueExpression.setValue(TagValueExpression.java:117)
at javax.faces.component.UIInput.updateModel(UIInput.java:380)
... 29 more
'setPdfPresets(字符串presetName)'是不是一個好主意,你應該只制定者和一致類型的干將;儘管你的評論表明這不是超載。 – Viruzzo 2012-03-20 12:43:44
對String使用額外的setter只是一個測試,試圖將返回的字符串寫入一個單獨的屬性。不幸的是,它沒有奏效。 – Rob 2012-03-20 12:49:11
將鼠標置於你自己提出問題的'[selectonemenu]'標記之上,然後單擊popbox上的* info *鏈接。 – BalusC 2012-03-20 13:09:51