JPA 容器或过滤器 - Vaadin 应用程序
JPA container OR filter - Vaadin application
我有一个 vaadin7 应用程序和一个用于实体的 JPA 容器 class。我有用于过滤该容器的 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 过滤器并添加到该过滤器?
Or
过滤器构造函数可以将过滤器数组作为参数,即您可以执行以下操作:
Filter[] filters = ...;
String[] ids = ...;
for (int i=0;i<10;i++) {
filters[i] = new Compare.Equal("brokerId.id", ids[i]);
}
Or or = new Or(filters);
我有一个 vaadin7 应用程序和一个用于实体的 JPA 容器 class。我有用于过滤该容器的 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 控件的最后一个值。
我需要的是为每个选定值
new Or(new Compare.Equal("brokerId.id", id1),new Compare.Equal("brokerId.id", id2),...)
当我迭代 ListSelect 控件的选定值时,是否可以创建 Or 过滤器并添加到该过滤器?
Or
过滤器构造函数可以将过滤器数组作为参数,即您可以执行以下操作:
Filter[] filters = ...;
String[] ids = ...;
for (int i=0;i<10;i++) {
filters[i] = new Compare.Equal("brokerId.id", ids[i]);
}
Or or = new Or(filters);