大家好,如果我以硬编码的方式将一个项目添加到带有ColumnGenerators的Vaadin表中,我总会得到一个Table.CacheUpdateException?
以下是代码:
// Generated Table columns
Table tableWithGeneratedCol = new Table();
tableWithGeneratedCol.addContainerProperty(
"date", Date.class, null, "Date", null, null);
tableWithGeneratedCol.addContainerProperty(
"quantity", Double.class, null, "Quantity (l)", null, null);
tableWithGeneratedCol.addContainerProperty(
"price", Double.class, null, "Price (e/l)", null, null);
tableWithGeneratedCol.addContainerProperty(
"total", Double.class, null, "Total (e)", null, null);
tableWithGeneratedCol.addItem(new Object[] { new GregorianCalendar().getTime(), // date column
new Double(10), // quantity column
new Double(10), // price column
new Double(0) // total column
}, 1); // itemId
tableWithGeneratedCol.addItem(new Object[] { new GregorianCalendar().getTime(),
new Double(16.2), // quantity column
new Double(21.2), // price column
new Double(0) // total column
}, 2); // itemId
tableWithGeneratedCol.addItem(new Object[] { new GregorianCalendar().getTime(),
new Double(10), // quantity column
new Double(22), // price column
new Double(0) // total column
}, 3); // itemId
tableWithGeneratedCol.addItem(new Object[] { new GregorianCalendar().getTime(),
new Double(10), // quantity column
new Double(20), // price column
new Double(0) // total column
}, 4); // itemId
tableWithGeneratedCol.addItem(new Object[] { new GregorianCalendar().getTime(),
new Double(15), // quantity column
new Double(19.12), // price column
new Double(0)
}, 5); // itemId
tableWithGeneratedCol.addItem(new Object[] { new GregorianCalendar().getTime(),
new Double(10), // quantity column
new Double(20.30), // price column
new Double(0) // total column
}, 6); // itemId
tableWithGeneratedCol.addItem(new Object[] { new GregorianCalendar().getTime(),
new Double(50), // quantity column
new Double(32.89), // price column
new Double(0) // total column
}, 7); // itemId
然后,如果我添加另一行:
tableWithGeneratedCol.addItem(new Object[] { new GregorianCalendar().getTime(),
new Double(50), // quantity column
new Double(32.89), // price column
new Double(0) // total column
}, 8); // itemId
我明白了:
SEVERE:
com.vaadin.ui.Table$CacheUpdateException: Error during Table cache update. Additional causes not shown.
at com.vaadin.ui.Table.maybeThrowCacheUpdateExceptions(Table.java:1739)
at com.vaadin.ui.Table.refreshRenderedCells(Table.java:1728)
at com.vaadin.ui.Table.attach(Table.java:4244)
at com.vaadin.ui.AbstractComponent.setParent(AbstractComponent.java:484)
at com.vaadin.ui.AbstractComponentContainer.addComponent(AbstractComponentContainer.java:210)
at com.vaadin.ui.AbstractOrderedLayout.addComponent(AbstractOrderedLayout.java:90)
at com.example.table_chapter_5_21.TableUI.init(TableUI.java:357)
at com.vaadin.ui.UI.doInit(UI.java:645)
at com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:222)
at com.vaadin.server.communication.UIInitHandler.synchronizedHandleRequest(UIInitHandler.java:74)
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1406)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:305)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1085)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1556)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1513)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
at java.util.Calendar.setTime(Calendar.java:1770)
at java.text.SimpleDateFormat.format(SimpleDateFormat.java:943)
at java.text.SimpleDateFormat.format(SimpleDateFormat.java:936)
at java.text.DateFormat.format(DateFormat.java:345)
at com.example.table_chapter_5_21.DateColumnGenerator.generateCell(DateColumnGenerator.java:27)
at com.example.table_chapter_5_21.DateColumnGenerator.generateCell(DateColumnGenerator.java:1)
at com.vaadin.ui.Table.parseItemIdToCells(Table.java:2334)
at com.vaadin.ui.Table.getVisibleCellsNoCache(Table.java:2195)
at com.vaadin.ui.Table.refreshRenderedCells(Table.java:1717)
... 34 more
Dec 19, 2014 10:24:58 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [com.example.table_chapter_5_21.TableUI$Servlet] in context with path [/Table_Chapter_5.21] threw exception [com.vaadin.server.ServiceException: com.vaadin.ui.Table$CacheUpdateException: Error during Table cache update. Additional causes not shown.] with root cause
java.lang.NullPointerException
at java.util.Calendar.setTime(Calendar.java:1770)
at java.text.SimpleDateFormat.format(SimpleDateFormat.java:943)
at java.text.SimpleDateFormat.format(SimpleDateFormat.java:936)
at java.text.DateFormat.format(DateFormat.java:345)
at com.example.table_chapter_5_21.DateColumnGenerator.generateCell(DateColumnGenerator.java:27)
at com.example.table_chapter_5_21.DateColumnGenerator.generateCell(DateColumnGenerator.java:1)
at com.vaadin.ui.Table.parseItemIdToCells(Table.java:2334)
at com.vaadin.ui.Table.getVisibleCellsNoCache(Table.java:2195)
at com.vaadin.ui.Table.refreshRenderedCells(Table.java:1717)
at com.vaadin.ui.Table.attach(Table.java:4244)
at com.vaadin.ui.AbstractComponent.setParent(AbstractComponent.java:484)
at com.vaadin.ui.AbstractComponentContainer.addComponent(AbstractComponentContainer.java:210)
at com.vaadin.ui.AbstractOrderedLayout.addComponent(AbstractOrderedLayout.java:90)
at com.example.table_chapter_5_21.TableUI.init(TableUI.java:357)
at com.vaadin.ui.UI.doInit(UI.java:645)
at com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:222)
at com.vaadin.server.communication.UIInitHandler.synchronizedHandleRequest(UIInitHandler.java:74)
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1406)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:305)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1085)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1556)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1513)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
然后,如果我等待一段时间然后重新加载页面,一切都会重新开始......
为什么这个例外?为什么使用ColumnGenerators?