Simple DataCollection Reference JPQL

Should be easy but I cannot figure it out. I think I tried everything from the docs.

I have some edit screen with a main data instance, let’s say “companyDc”.
The company entity has a field “city” which is a simple string, no reference.
I want to add a table to the edit screen with all companies in the same city.

So i create a new datacollection “otherCompaniesInTheSameCityDc”.
What is the correct query syntax for “select e from xx_company e where e.city = companyDc.city

Mentioning here, replacing companyDc.city by some static string 'Berlin' works.

I tried everything i found in the docs like “:param, :component, :container...”, underscores, dollar-signs, jpql_conditions (<condition>...</condition>).

Thanks.

Hi,
It’s not possible to do what you need by using only XML definition.

You should introduce a custom argument in the query and assign value for this argument in the screen controller (e.g. in BeforeShowEvent handler).

Example of query in data loader:

select e from xx_company e where e.city = :companyCity

Then set this parameter in screen controller before the data is loaded:

    @Inject
    private CollectionLoader<Company> otherCompaniesInTheSameCityDl;

    @Inject
    private InstanceContainer<Company> companyDc;

    @Subscribe
    private void onBeforeShow(BeforeShowEvent event) {
        otherCompaniesInTheSameCityDl.setParameter("companyCity", 
             getEditedEntity().getCity());
    }


1 Like

I did it as described and it works for a data collection.
Now i wanted to do the same with a data instance and i get an “access denied”.

    <instance id="wassetDc" class="com.test.entity.Wasset">
        <view extends="_local"/>
        <loader id="wassetDl">
            <query>
                <![CDATA[select e from vtw_Wasset e where e.str= :str]]>
            </query>
        </loader>
    </instance>

with

@Inject
private InstanceLoader<Wasset> wassetDl;

@Subscribe
public void onBeforeShow(BeforeShowEvent event) {
   wassetDl.setParameter("str", "somestring");
   wassetDl.load();
}

Same thing works with a Collection Loader instead od Instance Loader
It also works with a static query

<![CDATA[select e from vtw_Wasset e where e.str= 'somestring']]>

The message “Access Denied” when i open the Browser does not really help me.