2015-07-20 70 views
0

我在Vaadin中创建了一个数据库连接。我已经建立了的JDBCConnectionPool后,我创造了这样一个TableQuery:想知道如何在Vaadin的“TableQuery”中设置过滤器

  TableQuery tq = new TableQuery("STRING", pool, new OracleGenerator()); 

然而,这是非常成功的,因为我能够获得拨款实体(查询返回的整个表)。

问题是我想过滤这个查询。我对这个主题的文档感到非常失望。 TableQuery.setFilters()方法的javadoc指出,我们需要一个包含过滤器的List。

我迄今为止的做法:

  List<Filter> filter = new ArrayList<Filter>(); 
      filter.add(new Equal("SURNAME", "SMITH")); 
      tq.setFilters(filter); 

这不只是什么。它甚至不会引发异常。该代码的工作原理与没有上述提到的那样。

有没有人有一些输入?

回答

0

对不起,很简单。我刚刚弄错了这个概念。你必须过滤容器。

像这样:

  // tq is the TableQuery (see code snippet provided in the question) 
      SQLContainer container = new SQLContainer(tq); 
      container.addContainerFilter(new Equal("SURNAME", "SMITH")); 

可以帮助别人避免这种 “陷阱”,P