這是我的代碼,其執行兩種方法:java.lang.NumberFormatException:對於輸入字符串:「類型」
<h:panelGroup> <br /><br />
<h:outputLabel id="yearLbl" value="Year:" />
<h:outputLabel id="selectType" /><br />
<h:selectOneMenu id="type" value="#{clController.type}">
<f:selectItem itemValue="2013" itemLabel="2013" />
<f:selectItem itemValue="2012" itemLabel="2012" />
<f:selectItem itemValue="2011" itemLabel="2011" />
<f:selectItem itemValue="2010" itemLabel="2010" />
<f:selectItem itemValue="2009" itemLabel="2009" />
<f:selectItem itemValue="2008" itemLabel="2008" />
</h:selectOneMenu>
<h:commandButton type="submit" onclick="#{clController.getTotal(clController.type)}" action="#{clController.getPaymentByMonth(clController.type)}" id="stateInfo" value="Show Monthly " >
</h:commandButton>
</h:panelGroup>
這些被稱爲功能:
public DataModel getPaymentByMonth(String year) {
this.session = HibernateUtil.getSessionFactory().getCurrentSession();
List<CustomerPayment> paymentList = null;
try {
org.hibernate.Transaction tx = session.beginTransaction();
Query q = session.createQuery("from CustomerPayment where DATE like '%" + year + "'");
paymentList = (List<CustomerPayment>) q.list();
} catch (Exception e) {
e.printStackTrace();
}
return paymentDataModel = new ListDataModel(paymentList);
}
public DataModel getTotal(String year) {
this.session = HibernateUtil.getSessionFactory().getCurrentSession();
List<CustomerPayment> total = null;
try {
org.hibernate.Transaction tx = session.beginTransaction();
System.out.println(year);
Query q = session.createQuery("select c.type, c.date, sum(c.amount) from CustomerPayment c where c.date LIKE '%"+year+"' group by c.type");
System.out.println("select c.type, c.date, sum(c.amount) from CustomerPayment c where c.date LIKE '%"+year+"' group by c.type");
total = (List<CustomerPayment>) q.list();
} catch (Exception e) {
e.printStackTrace();
}
return totalDataTable = new ListDataModel(total);
}
的問題是,我得到這個錯誤:
java.lang.NumberFormatException: For input string: "type"
的類型意味着多年,但我給出了錯誤這一點。當我打印類型到屏幕它爲2013年打印爲什麼我得到這個錯誤?
完整堆棧跟蹤:
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:481)
at java.lang.Integer.parseInt(Integer.java:514)
at javax.el.ArrayELResolver.coerce(ArrayELResolver.java:166)
at javax.el.ArrayELResolver.getValue(ArrayELResolver.java:46)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at org.apache.el.parser.AstValue.getValue(AstValue.java:183)
at org.apache.el.parser.AstDeferredExpression.getValue(AstDeferredExpression.java:44)
at org.apache.el.parser.AstCompositeExpression.getValue(AstCompositeExpression.java:50)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
at javax.faces.component.UIOutput.getValue(UIOutput.java:169)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312)
at com.sun.faces.renderkit.html_basic.OutputLinkRenderer.encodeChildren(OutputLinkRenderer.java:124)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:304)
at com.sun.faces.renderkit.html_basic.TableRenderer.renderRow(TableRenderer.java:385)
at com.sun.faces.renderkit.html_basic.TableRenderer.encodeChildren(TableRenderer.java:162)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:304)
at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:105)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:424)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:124)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:679)
是的,完整的堆棧跟蹤會有所幫助。 – 2013-05-01 11:59:45