How to pass an entity parameter to a standard lookup screen

Hi

I have a problem very similar to this one (and many other related posts), but I would like to pass an entity through a standard action.

I have a Customer editor screen with a table opening a Contact lookup screen through the standard action “add”. I would like to pass the Customer currently being edited to the Contact lookup screen in order to add optional filtering on the Customer Contacts.

I customized the query in the Contact lookup screen in order to handle it.


<query>
                <![CDATA[select e from busy$Contact e]]>
                <filter>
                    <or>
                        <c>e.customer = :custom$customer</c>
                        <c>e.customer is null</c>
                    </or>
                </filter>
            </query>

Now I need to pass :custom$customer to the lookup screen. For now I discarded these solutions :

  • inject “contacts.add” action, then setwindowsParams(…) in Customer editor postInit() method, because this is static (what if Customer changes ?)
  • create a custom ‘add’ action and a custom Contact browser (the default ones fit me well apart from that)

EDIT : I gave a try to the first solution (and jpql tweaks) and it works. If I understand correctly postInit() is called each time the edited entity changes so it seems my case is fulfilled, right ?

Ideally I would like to set the Customer param at the moment the standard ‘add’ action calls ‘openLookup’ to be sure the Customer entity sent to the Contact browser is current and will not change (especially when a modal dialog is used).

In fact, the point is very similar to the ‘screen manipulation’ sample, but it uses code to open the Product lookup, which I do not.

Mike

Hi Mike,

You can safely use action.setWindowParams(ParamsMap.of(“customer”, getItem())) in editor’s postInit() method, because it is invoked each time you start editing an entity.

In order to get parameter values right before the action is invoked, you have to create a subclass of the standard action and override its getWindowParams() method returning the map of parameters from it. For example:

table.addAction(new AddAction(table) {
    @Override
    public Map<String, Object> getWindowParams() {
        return ParamsMap.of("customer", getItem());
    }
});

Also note that you can use window parameters directly in your datasource query like this (see param$ prefix), so you dont need to pass it in refresh():

<query>
    <![CDATA[select e from busy$Contact e]]>
    <filter>
        <or>
            <c>e.customer = :param$customer</c>
            <c>e.customer is null</c>
        </or>
    </filter>
</query>
1 Like

Thanks Konstantin. I had already figured out the ‘custom’ vs ‘param’ issue in my query code. Good to know for the override of ‘getWindowsParam()’, may I suggest this small point is documented in the ‘standard actions’ section of the docs.

I would also suggest that the difference between ‘custom’ and ‘param’ be more clear in the doc. Especially with a code snippet with the ‘WindowParam’ annotation that I discovered otherwhere while reading. That fits well with the ‘param’ example.

Another small improvement I would suggest in the doc is to not hide the CDATA encapsulation part of the query in the examples provided in ‘query parameters’ and ‘query filter’ section.

Thanks for the feedback. Will do.