Error on saved filter with BaseIntegerIdEntity

Hi!

I have an issue with previously saved filters.
In my project I have an entity(NewEntity_1), which have an attribute(a) of another entity(NewEntity). Both entities extend BaseIntegerIdEntity.
I open the browser of NewEntity_1 and create a filter of the attribute ‘A’. I choose the NewEntity named ‘asd’.
image
All works fine.
After this I save the filter with values.
image
I reopen the browser, choose the previously saved filter from the filters. I get this error:
image

java.lang.IllegalArgumentException: Invalid UUID string: 1
at java.util.UUID.fromString(UUID.java:194)
at com.haulmont.cuba.gui.components.filter.Param.loadEntity(Param.java:381)
at com.haulmont.cuba.gui.components.filter.Param.parseSingleValue(Param.java:333)
at com.haulmont.cuba.gui.components.filter.Param.parseValue(Param.java:325)
at com.haulmont.cuba.gui.components.filter.condition.AbstractCondition.resolveParam(AbstractCondition.java:197)
at com.haulmont.cuba.gui.components.filter.condition.AbstractCondition.(AbstractCondition.java:140)
at com.haulmont.cuba.gui.components.filter.condition.PropertyCondition.(PropertyCondition.java:55)
at com.haulmont.cuba.gui.components.filter.FilterParserImpl.createCondition(FilterParserImpl.java:94)
at com.haulmont.cuba.gui.components.filter.FilterParserImpl.recursiveFromXml(FilterParserImpl.java:63)
at com.haulmont.cuba.gui.components.filter.FilterParserImpl.getConditions(FilterParserImpl.java:49)
at com.haulmont.cuba.gui.components.filter.FilterDelegateImpl.setFilterEntity(FilterDelegateImpl.java:538)
at com.haulmont.cuba.gui.components.filter.FilterDelegateImpl$7.actionPerform(FilterDelegateImpl.java:1116)

The problem:

Param.java:381
LoadContext ctx = new LoadContext(javaClass).setId(UUID.fromString(id));

Filter xml:

<filter>
<and>
<c name=“a” class=“com.company.untitled.entity.NewEntity” operatorType=“EQUAL” width=“1” type=“PROPERTY”>
<param name=“component$filter.a12313” javaClass=“com.company.untitled.entity.NewEntity”>1
</c>
</and>
</filter>

Can you suggest any workarounds and can you fix this bug in the later versions?
Thanks,
Julia

Hi Julia,

It seems you’ve confused the visual component Filter and the datasource query filter. You don’t need to modify the screen descriptor, just select “Save with values” and then “Make default” in the Filter editor in your application, and the browse screen will always be opened with the filtered data.

Hi Olga!

Thanks for your reply. :slight_smile:
I appreciate you trying to help, but I don’t see why making it default would change anything :smiley:
(for the record we did make the same filter default and that only made the error always pop up when the browse screen is opened and the table not filtered at all)
I thought I clearly stated that I didn’t change anything in the screen descriptor…
That’s the xml that was saved in the db in the sec_filter table…

But as usual if there is a bug I have to hack around it 'cause no version upgrade fixes it :slight_smile:
I ended up writing a BeforeInsertEntityListener<FilterEntity> and manualy changeing the filter xml. It looks awful but at least it’s working and not throwing errors.
If anyone needs it:

public class FilterEntityListener
    implements BeforeInsertEntityListener<FilterEntity>, BeforeUpdateEntityListener<FilterEntity> {
@Override
public void onBeforeInsert(FilterEntity entity, EntityManager entityManager) {
    entity.setXml(fixIntegerID(entity.getXml()));
}

@Override
public void onBeforeUpdate(FilterEntity entity, EntityManager entityManager) {
    entity.setXml(fixIntegerID(entity.getXml()));
}

private String fixIntegerID(String xml) {
    String[] c = xml.split("<c");
    String intParam = "";
    for (String x : c){
        if(x.contains("class=\"com.company.untitled.entity") && x.contains("operatorType=\"EQUAL\"")){
            intParam = x;
            String classSearch = "class=\"";
            String classString = x.substring(x.indexOf(classSearch) + classSearch.length(), x.indexOf("\"", x.indexOf(classSearch) + classSearch.length()));
            intParam = intParam.replaceAll(classString, "java.lang.Integer");
            String nameSearch = "name=\"";
            String nameString = x.substring(x.indexOf(nameSearch), x.indexOf("\"", x.indexOf(nameSearch) + nameSearch.length()));
            intParam = intParam.replace(nameString, nameString + ".id");
            xml = xml.replace(x,intParam);
        }
    }
    return xml;
}

}

Thank you for reporting the bug, we’ve reproduced it and created an issue on GitHub to fix it.

1 Like

Thank you :slight_smile: