Title: How to persist filter values across different views in Jmix 2+?
Description:
Hi,
I’m developing a web application using Jmix 2.2.5 and Spring Boot 3.2. I want to persist the values of filter fields in a ListView, so that when I return to the view (even after visiting other views), the previously entered filter values are still set.
I’ve tried using a @VaadinSessionScope bean to store the filter values, restore them in the BeforeShow/ReadyEvent and reload the data provider, but the solution is not working as expected. The filter values are not always restored.
Has anyone implemented a similar feature? Is there an official or recommended approach to achieve persistent filter fields across navigation in Jmix?
I think the simplest way to store values from PropertyFilters is to use the settings facet. It saves values in the database for a specific user and view, including any provided settings.
For example, add the settings facet to the XML and inject it into the controller:
<settings id="settingsFacet" auto="true"/>
You can remove the auto attribute or set it to false if you do not want the facet to save the states of other components.
If you want to store settings in memory, it is better to use the @UIScope annotation instead of the session scope. This is because in the case of session scope, you also need to store information about the UI instance. Otherwise the stored values will be shared across multiple web browser tabs showing the same view.