我正在使用com.vaadin.data.util.sqlcontainer.query.TableQuery
使用来自MYSQL表的数据填充UI视图。
我想只显示特定字段为空的行,因此原始SQL为:
SELECT * FROM products WHERE monthsLeft IS null;
引用Vaadin docs,我使用Vaadin SQLContainer对象将此条件设置为
sqlContainer.addContainerFilter(new Compare.Equal("monthsLeft ", null));
但是这会引发以下错误:
Sep 11, 2014 5:10:13 PM com.vaadin.server.DefaultErrorHandler doDefault
SEVERE:
java.lang.IllegalArgumentException: You cannot add null parameters using addParamaters(Object). Use addParameters(Object,Class) instead
at com.vaadin.data.util.sqlcontainer.query.generator.StatementHelper.addParameterValue(StatementHelper.java:63)
at com.vaadin.data.util.sqlcontainer.query.generator.filter.CompareTranslator.getWhereStringForFilter(CompareTranslator.java:32)
at com.vaadin.data.util.sqlcontainer.query.generator.filter.QueryBuilder.getWhereStringForFilter(QueryBuilder.java:82)
at com.vaadin.data.util.sqlcontainer.query.generator.filter.QueryBuilder.getJoinedFilterString(QueryBuilder.java:92)
at com.vaadin.data.util.sqlcontainer.query.generator.filter.QueryBuilder.getWhereStringForFilters(QueryBuilder.java:107)
at com.vaadin.data.util.sqlcontainer.query.generator.DefaultSQLGenerator.generateSelectQuery(DefaultSQLGenerator.java:107)
at com.vaadin.data.util.sqlcontainer.query.TableQuery.getCount(TableQuery.java:200)
at com.vaadin.data.util.sqlcontainer.SQLContainer.updateCount(SQLContainer.java:1142)
at com.vaadin.data.util.sqlcontainer.SQLContainer.size(SQLContainer.java:398)
at com.vaadin.ui.AbstractSelect.size(AbstractSelect.java:762)
at com.vaadin.ui.Table.refreshRenderedCells(Table.java:1628)
at com.vaadin.ui.Table.getVisibleCells(Table.java:3921)
at com.vaadin.ui.Table.beforeClientResponse(Table.java:3155)
at com.vaadin.server.communication.UidlWriter.write(UidlWriter.java:96)
at com.vaadin.server.communication.UidlRequestHandler.writeUidl(UidlRequestHandler.java:149)
at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:97)
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:37)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1329)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:236)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:503)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
我希望有一个Compare.IsNull
,但我没有看到一个
答案 0 :(得分:0)
查看源代码,这似乎不可能。
此方法没有'IS NULL'的情况:
@Override
public String getWhereStringForFilter(Filter filter, StatementHelper sh) {
Compare compare = (Compare) filter;
sh.addParameterValue(compare.getValue());
String prop = QueryBuilder.quote(compare.getPropertyId());
switch (compare.getOperation()) {
case EQUAL:
return prop + " = ?";
case GREATER:
return prop + " > ?";
case GREATER_OR_EQUAL:
return prop + " >= ?";
case LESS:
return prop + " < ?";
case LESS_OR_EQUAL:
return prop + " <= ?";
default:
return "";
}
}
引用的方法(addParameters(Object,Class))仅从三个方法调用,名称为generateDeleteQuery,generateInsertQuery和generateUpdateQuery。
虽然提交补丁不应该太难;)
答案 1 :(得分:0)
我开始查看源代码来编写补丁,我找到了com.vaadin.data.util.filter。 IsNull 。
解决方案是:
sqlContainer.addContainerFilter(new IsNull("monthsLeft"));