viagdo3
(Vicente Aguilar)
November 28, 2024, 3:50pm
1
Hi,
we are evaluating the split of our full stack JMIX application to have a separated frontend and a backend so we integrate them through REST Datastore. When evaluating this apporach we found the generic filter does not work or we don’t know how to make it work properly with Data Store entities.
So is Rest Datastore compatible with that great feature that is the generic filter?
If not is there any sample or experience we can check for implementing something similar in terms of configuration and parameterization like saving filters, select fields etc…?
Thanks in advance!
krivopustov
(Konstantin Krivopustov)
December 2, 2024, 11:16am
3
Hi Vicente,
The GenericFilter component is fully compatible with REST DataStore. It doesn’t work in Jmix 2.4.1 because of this bug:
opened 05:40AM - 26 Nov 24 UTC
closed 01:39PM - 03 Dec 24 UTC
type: bug
size: S
in: flowui
### Environment
Jmix version: 2.4.1
### Bug Description
Exception occur… s when clicking "Add search condition" in a generic filter bound to a data loader without a JPQL query:
```
java.lang.NullPointerException: Cannot invoke "String.indexOf(String)" because "query" is null
at io.jmix.flowui.component.genericfilter.FilterMetadataTools.getMainFromMetaClass(FilterMetadataTools.java:185)
at io.jmix.flowui.component.genericfilter.FilterMetadataTools.belongToCrossDataStoreReference(FilterMetadataTools.java:154)
at io.jmix.flowui.component.genericfilter.FilterMetadataTools.isMetaPropertyPathAllowedJpaAware(FilterMetadataTools.java:129)
at io.jmix.flowui.component.genericfilter.FilterMetadataTools.isMetaPropertyPathAllowed(FilterMetadataTools.java:120)
at io.jmix.flowui.component.genericfilter.FilterMetadataTools.getPropertyPaths(FilterMetadataTools.java:94)
at io.jmix.flowui.component.genericfilter.FilterMetadataTools.getPropertyPaths(FilterMetadataTools.java:72)
at io.jmix.flowui.component.genericfilter.builder.PropertyConditionBuilder.build(PropertyConditionBuilder.java:75)
at io.jmix.flowui.component.genericfilter.builder.GenericFilterConditionsBuilder.buildConditions(GenericFilterConditionsBuilder.java:44)
at io.jmix.flowui.action.genericfilter.GenericFilterAddConditionAction.execute(GenericFilterAddConditionAction.java:135)
at io.jmix.flowui.action.genericfilter.GenericFilterAction.actionPerform(GenericFilterAction.java:85)
at io.jmix.flowui.kit.component.button.JmixButtonActionSupport.onButtonClick(JmixButtonActionSupport.java:151)
```
### Sample Project
https://github.com/jmix-framework/jmix-separate-tiers-sample
It will be fixed in the next patch (2.4.2) which will be available in December.
Meanwhile, you can fix the problem in your project as follows:
Create a bean overriding the one from the framework:
package com.company.frontend;
import io.jmix.core.AccessManager;
import io.jmix.core.Metadata;
import io.jmix.core.MetadataTools;
import io.jmix.core.metamodel.model.MetaProperty;
import io.jmix.core.metamodel.model.MetaPropertyPath;
import io.jmix.flowui.UiComponentProperties;
import io.jmix.flowui.component.genericfilter.FilterMetadataTools;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
@Primary
@Component
public class MyFilterMetadataTools extends FilterMetadataTools {
public MyFilterMetadataTools(MetadataTools metadataTools, UiComponentProperties uiComponentProperties, AccessManager accessManager, Metadata metadata) {
super(metadataTools, uiComponentProperties, accessManager, metadata);
}
@Override
protected boolean belongToCrossDataStoreReference(MetaPropertyPath propertyPath, String query) {
for (int i = 0; i < propertyPath.getMetaProperties().length - 1; i++) {
MetaProperty parentMetaProperty = propertyPath.getMetaProperties()[i];
if (isCrossDataStoreReference(parentMetaProperty)) {
return true;
}
}
return false;
}
}
Add the application property:
jmix.core.exclude-beans = flowui_UiDataFilterMetadataTools
Regards,
Konstantin