Filter Component Default Value

Good morning to everyone.
I´m struggling with this problem for weeks–> I have a Browse that contains many filter configurations. So for every filter configuration I want to set some default values for components.
Code
With this code happens some things :sweat_smile: :
When the browse is loaded default filter have the values that I want (current day)
1
When I change to another filter, current date don´t apply
otro filtro
When I go back to original filter, values are incorrect again:
2

Filter parameters name are ok… I´m using SessionData to set attribute (hasta) to current date when I first open the app so I can request everytime I want.
I´m using JPQL condition:
3

Thank you very much in advance.

Perhaps you should subscribe to ConfigurationChangeEvent and set your desired values in the handler.

Hello sorry for this late answer.
In ConfigurationChangeEvent I cannot use .loadConfigurationsAndApplyDefault() because the app enter in a infinite loop. If I don´t use this method, default values are aplyied BUT I can see them only if I go to edit the filter… see–>
1
Now if I go to edit this filter…—>
2
If I press “OK” the values are aplyied in the browse… if “Cancel” is pressed, browse values keep empty.

Perhaps at this stage you need to set the value directly to the component.

For example, if you create a By username configuration in the user browse filter and set the parameter name to usernamejDSJwvYM, the following code will set the parameter value to ad whenever you select this configuration:

@Subscribe("filter")
public void onFilterConfigurationChange(Filter.ConfigurationChangeEvent event) {
    Filter.Configuration configuration = event.getNewConfiguration();
    if ("By username".equals(configuration.getName())) {
        setFilterComponentValue(configuration, "usernamejDSJwvYM", "ad");
    }
}

private static void setFilterComponentValue(Filter.Configuration configuration,
                                            String name, Object value) {
    configuration.getRootLogicalFilterComponent().getFilterComponents().stream()
            .filter(filterComponent ->
                    filterComponent instanceof SingleFilterComponent
                        && name.equals(((SingleFilterComponent<?>) filterComponent).getParameterName()))
            .findFirst()
            .ifPresent(filterComponent ->
                    ((SingleFilterComponent<Object>) filterComponent).getValueComponent().setValue(value));
}
2 Likes

It works, I´m very grateful with your help

Thank you, Kind regards