我有一个实体类的 vaadin7 应用程序和一个 JPA 容器。我有用于过滤该容器的 ListSelect 控件
private ListSelect generateBrokerSelects() {
ListSelect broker_ListSelect = new ListSelect("Broker:");
JPAContainer<ReservationsBroker> containerBroker = JPAContainerFactory.makeReadOnly(ReservationsBroker.class, em);
containerBroker.sort(new Object[]{"name"}, new boolean[]{true});
broker_ListSelect.setContainerDataSource(containerBroker);
broker_ListSelect.setMultiSelect(true);
broker_ListSelect.setRows(4);
broker_ListSelect.setItemCaptionPropertyId("name");
return broker_ListSelect;
}
我想根据在此 ListSelect 控件上选择的值过滤 JPA 容器。
public List<Container.Filter> getFilters() {
List<Container.Filter> filters = new LinkedList<>();
Container.Filter filter;
Set brokerList = (Set) broker_ListSelect.getValue();
if (brokerList.size() > 0) {
for (Object brokerId : brokerList) {
filter = new Compare.Equal("brokerId.id", brokerId);
filters.add(filter);
}
return filters;
}
private void applyFilters() {
container.removeAllContainerFilters();
for (Container.Filter filter : getFilters()) {
container.addContainerFilter(filter);
}
}
上面代码的问题是它有效地将“AND”过滤器添加到容器中,所以我只剩下 ListSelect 控件的最后一个值。
我需要的是为每个选定的值创建一个包含 Compare.Equal 的 OR 过滤器
new Or(new Compare.Equal("brokerId.id", id1),new Compare.Equal("brokerId.id", id2),...)
当我迭代 ListSelect 控件的选定值时,有没有办法创建 Or 过滤器并添加到该过滤器?