Accessing the SearchForm from a TablePage [message #1780396] |
Mon, 22 January 2018 07:47 |
Urs Beeli Messages: 573 Registered: October 2012 Location: Bern, Switzerland |
Senior Member |
|
|
We are using extensions to AbstractPageWithTable in which we use getConfiguredSearchForm() to define the search form. We then implement the execLoadData() method, which is called when the search button is pressed. It takes a SearchFilter parameter from which we can get the pre-filled SearchFormData object containing our search criteria. This object is then passed to our OutlineService implementation which uses it to retrieve the required data from our backend. As we keep our backend scout-free, we are moving the contents of the SearchFormData class into another DTO which we then pass from the OutlineService into our backend layer. We have succesfully been using this approach for a few years.
So far, so good.
However, as we are migrating from Eclipse to IntelliJ as IDE we no longer have the possiblity to auto-generate the SearchFormData from the SearchForm (this is done by the Eclipse Scout Plugin). Our idea is to do without the SearchFormData and instead already populate our own DTO in the client instead of the server. The idea is to do this in the AbstractPageWithTable.execLoadData() method of our table page, we would like to get access to the search form, so we could retrieve the field contents and write those into our DTO, we would then call the OutlineService with this DTO instead of the SearchFormData.
The problem is, that I don't currently see how we can access the SearchForm from our TablePage. The SearchFilter bean does not seem to contain a reference to the SearchForm. Is there any way to get a reference to the SearchForm instance? We do know its class (thanks to getConfiguredSearchForm), is there a way to ask Scout for the instance of that class? Can we just use BEANS.get(MySearchForm.class)?
|
|
|
|
Re: Accessing the SearchForm from a TablePage [message #1780416 is a reply to message #1780396] |
Mon, 22 January 2018 10:05 |
Eclipse User |
|
|
|
In addition to Stephan Merklis replay some code examples.
TablePage
@ClassId("42f088a6-d93a-41cc-b6fd-2fc780494fd0")
public class PersonTablePage extends AbstractPersonTablePage<Table> {
...
@Override
protected void execPopulateTable() {
getTable().replaceRows(BEANS.get(IPersonService.class)
.findPersons(new PersonSearchQuery().withFirstName(getSearchFormInternal().getFirstNameField().getValue()))
.stream().map(person -> {
ITableRow row = getTable().createRow();
row.getCellForUpdate(getTable().getIdColumn()).setValue(person.getId());
row.getCellForUpdate(getTable().getFirstNameColumn()).setValue(person.getFirstName());
row.getCellForUpdate(getTable().getLastNameColumn()).setValue(person.getLastName());
return row;
}).collect(Collectors.toList()));
}
@Override
protected Class<? extends ISearchForm> getConfiguredSearchForm() {
return PersonSearchForm.class;
}
@Override
public PersonSearchForm getSearchFormInternal() {
return (PersonSearchForm) super.getSearchFormInternal();
}
...
}
Person and PersonQuery are simple POJOs.
findPersons on the PersonService returns a List<Person>.
/andreas
|
|
|
|
Powered by
FUDForum. Page generated in 0.03289 seconds