Filter on a nested datasource

Dear All,

I have a header entity BillingCycles with a detail entity called BillingAdjustments. The later is defined as an ASSOCIATION field on the BillingCycles entity.
On the detail level, I am implementing a “posting” functionality which posts the billing adjustment detail line by changing its posted field to true.
Once this is done, I need to remove it from the detail view. In other terms, the detail datasource should only show lines pertaining to the header billing cycle but with posted = false.

I cannot set this on the nested datasource level since there is no query window at this level.
I tried to write it on the xml file of the screen but this is not taking any effect.


 <collectionDatasource id="billingAdjustmentsDs"
                                  property="billingAdjustments"/>
                                  <query>
                <![CDATA[select e from billing$BillingAdjustments e
where e.posted = false]]>
            </query>
        </collectionDatasource>

I tried to set the filter on the init() method, but this resulted in an UnsupportedOperationException:
java.lang.UnsupportedOperationException
at com.haulmont.cuba.gui.data.impl.CollectionPropertyDatasourceImpl.refresh(CollectionPropertyDatasourceImpl.java:691)
at com.company.billing.web.billings.PendingbillingsBrowse.lambda$init$0(PendingbillingsBrowse.java:80)
at com.haulmont.bali.events.EventRouter.fireEvent(EventRouter.java:45)
at com.haulmont.cuba.web.gui.components.WebLookupField.lambda$attachListener$4850968e$1(WebLookupField.java:203)
at sun.reflect.GeneratedMethodAccessor118.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)


Map<String, Object> adjustmentParams = new HashMap<String, Object>();
adjustmentParams.put("posted", false);
billingAdjustmentsDs.refresh(adjustmentParams);

What is the solution to fulfill this simple requirement?

Appreciate your prompt feedback.

Regards,

Shady

Hi Shady,

Use a standalone collection datasource linked with ds$ parameter instead of the nested datasource. See an example here: customer-edit.xml.

Thanks Konstantin.

But using this method, will I be able to create new record on the line level? Will they automatically take the ID of the header record when creating new details like in the case of Association attribute?

You probably confuse ASSOCIATION and COMPOSITION relations. When you define a OneToMany property as COMPOSITION, Studio will generate nested datasource and table for the lines part. If you use ASSOCIATION, you will have to add all this manually to screen. Add also Create, Edit and Remove actions and for Create action use setInitialValues() method to initialize the reference to owning entity. See an example of using this method in the docs.

Sorry I meant to say COMPOSITION in my previous question.

In my previous design, I used ASSOCIATION and created everything manually, but failed to retrieve the header key and set it on the detail screen. That is why I decided to go for the COMPOSITION design, but then got stuck on the filtering constraint which is why I am posting this question.

So following your recommendations, there is no solution but to revert back to the ASSOCIATION old design and use the method you are referring to.

Thanks for your continuous help.

Hi Konstantin,

Thanks, it worked like a charm!