How to create filters on dto entity browse screen same like other browse ui screen.
Filter UI component modifies JPQL query used for loading entities, so it won’t work with DTO entities. What you can do is to define your own filter, i.e. add a fixed number of fields to the screen and use its values when you load your DTO list.
For example, you have a screen where you display a list of Customer DTO. You may add two fields for filtering values: firstName and lastName:
<groupBox id="filterBox" spacing="true" orientation="horizontal" caption="msg://filter" expand="spring">
<label value="msg://firstName" align="MIDDLE_LEFT"/>
<textField id="firstNameFilter" datatype="string"/>
<label value="msg://lastName" align="MIDDLE_LEFT"/>
<textField id="lastNameFilter" datatype="string"/>
<button id="refreshBtn" caption="msg://refresh" icon="REFRESH"/>
<hbox id="spring"/>
</groupBox>
The DataLoader delegate should analyze these field values and load data using the filtering criteria:
@UiController("Customer.browse")
@UiDescriptor("customer-browse.xml")
@LookupComponent("customersTable")
public class CustomerBrowse extends StandardLookup<Customer> {
@Autowired
private CustomerService customerService;
@Autowired
private CollectionLoader<Customer> customersDl;
@Autowired
private TextField<String> firstNameFilter;
@Autowired
private TextField<String> lastNameFilter;
@Install(to = "customersDl", target = Target.DATA_LOADER)
private List<Customer> customersDlLoadDelegate(LoadContext<Customer> loadContext) {
String firstNameFilterValue = firstNameFilter.getValue();
String lastNameFilterValue = lastNameFilter.getValue();
return customerService.loadCustomers(firstNameFilterValue, lastNameFilterValue);
}
@Subscribe("refreshBtn")
public void onRefreshBtnClick(Button.ClickEvent event) {
customersDl.load();
}
}
The sample demonstrating this approach: dto-filter-sample.zip (87.1 KB)
Thank you Maxim Gorbunkov for helping.