错误:
我正在尝试在我的SQLContainer上实现自定义容器过滤器,以过滤掉在特定日期之前设置的日期。我在运行应用程序时遇到错误,但我不确定这是否是一个错误。
maj 20, 2016 10:40:26 FM com.vaadin.server.DefaultErrorHandler doDefault
ALLVARLIG: java.lang.RuntimeException: Failed to update item set size.
at com.vaadin.data.util.sqlcontainer.SQLContainer.updateCount(SQLContainer.java:1181)
at com.vaadin.data.util.sqlcontainer.SQLContainer.size(SQLContainer.java:403)
at com.vaadin.ui.Table.containerItemSetChange(Table.java:4565)
at com.vaadin.data.util.sqlcontainer.SQLContainer.fireContentsChange(SQLContainer.java:1633)
at com.vaadin.data.util.sqlcontainer.SQLContainer.refresh(SQLContainer.java:910)
at com.vaadin.data.util.sqlcontainer.SQLContainer.refresh(SQLContainer.java:892)
at com.vaadin.data.util.sqlcontainer.SQLContainer.addContainerFilter(SQLContainer.java:550)
at com.example.appletini_v01.ViewMain.calcStats(ViewMain.java:466)
at com.example.appletini_v01.ViewMain$5.buttonClick(ViewMain.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:508)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:198)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161)
at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:1008)
at com.vaadin.ui.Button.fireClick(Button.java:377)
at com.vaadin.ui.Button$1.click(Button.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:158)
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:118)
at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:408)
at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:273)
at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:79)
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1409)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:364)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
at com.mysql.jdbc.Util.getInstance(Util.java:387)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:939)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2478)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2625)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2551)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1962)
at com.vaadin.data.util.sqlcontainer.query.TableQuery.executeQuery(TableQuery.java:529)
at com.vaadin.data.util.sqlcontainer.query.TableQuery.getCount(TableQuery.java:210)
at com.vaadin.data.util.sqlcontainer.SQLContainer.updateCount(SQLContainer.java:1170)
... 52 more
maj 20, 2016 10:40:27 FM com.vaadin.server.DefaultErrorHandler doDefault
ALLVARLIG: java.lang.RuntimeException: Failed to update item set size.
at com.vaadin.data.util.sqlcontainer.SQLContainer.updateCount(SQLContainer.java:1181)
at com.vaadin.data.util.sqlcontainer.SQLContainer.size(SQLContainer.java:403)
at com.vaadin.ui.AbstractSelect.size(AbstractSelect.java:792)
at com.vaadin.ui.Table.doPaintContent(Table.java:3318)
at com.vaadin.ui.Table.paintContent(Table.java:3302)
at com.vaadin.server.LegacyPaint.paint(LegacyPaint.java:65)
at com.vaadin.server.communication.LegacyUidlWriter.write(LegacyUidlWriter.java:82)
at com.vaadin.server.communication.UidlWriter.write(UidlWriter.java:145)
at com.vaadin.server.communication.UidlRequestHandler.writeUidl(UidlRequestHandler.java:113)
at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:81)
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1409)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:364)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
at com.mysql.jdbc.Util.getInstance(Util.java:387)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:939)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2478)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2625)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2551)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1962)
at com.vaadin.data.util.sqlcontainer.query.TableQuery.executeQuery(TableQuery.java:529)
at com.vaadin.data.util.sqlcontainer.query.TableQuery.getCount(TableQuery.java:210)
at com.vaadin.data.util.sqlcontainer.SQLContainer.updateCount(SQLContainer.java:1170)
... 34 more
代码:
我使用this页面底部的代码作为开头,最后得到了以下代码。我不确定它是否完美,但我的问题不在于代码本身,而是在运行应用程序时弹出的错误。
class StartDateFilter implements Container.Filter {
protected String propertyId;
protected Date date;
public StartDateFilter(String propertyId, Date date) {
this.propertyId = propertyId;
this.date = date;
}
/** Tells if this filter works on the given property. */
public boolean appliesToProperty(Object propertyId) {
return propertyId != null &&
propertyId.equals(this.propertyId);
}
/** Apply the filter on an item to check if it passes. */
public boolean passesFilter(Object itemId, Item item)
throws UnsupportedOperationException {
// Acquire the relevant property from the item object
Property p = item.getItemProperty(propertyId);
// Should always check validity
if (((Date) p).getTime() < date.getTime()) {
return false;
}
return true;
}
}
该课程后来在这里使用:
// Filter settings
currContainer.removeAllContainerFilters();
// Apply filters
if (combo.getValue() != null) {
Filter folderFilter = new SimpleStringFilter("inParm", combo.getValue().toString(), true, false);
currContainer.addContainerFilter(folderFilter);
}
if (dateStart.getValue() != null) {
// TODO Add a filter for the start-date
currContainer.addContainerFilter(new StartDateFilter("Start", (Date) dateStart.getValue()));
}
if (dateStop.getValue() != null) {
// TODO Add a filter for the stop-date
}
folderFilter工作正常。导致错误的是StartDateFilter。
我尝试将代码剥离到最基本的组件,例如只返回true,但似乎没有任何东西能够更新项目集大小。这里似乎有某种错误。这也在Vaadin论坛的this帖子中进行了讨论。
问题: