How to add a filter to an association field

Hi,

I have an edit screen (entity Company) that one of the fields is a association with the City entity. When the user clicks this field to select a City, I would like to open the City Browser with a filter (only cities in a region). How can I define this filter?

Thank you,

Claudio

Hi,

Use query params & query filter
On browse screen of City entity:

<collectionDatasource id="citiesDs" class="com.sample.entity.City" view="browse">
<query>
    <![CDATA[select e from <prefix>$City e ]]>
    <filter>
        <and>
            <c>e.region.id = :param$region</c>
        </and>
    </filter>
</query>
</collectionDatasource>

Use the PickerField or LookupPikerField for City field.
Modify lookup action on this screen component and add code in screen Controller

@Inject
protected PickerField cityField;
...
@Override
public void init(Map<String, Object> params) {
    RegionEntity region =<same code>
    PickerField.LookupAction action = cityField.getActionNN("lookup");
    action.setLookupScreenParams("region", region) 
}
1 Like

Hello Kirill,

Thank you a lot!

Claudio

1 Like