How to customize a generic browser view

Hello dear Cuba Support Team,

I plan to have a Browser view with two tables, one main table for customer entities on the top, the table at the bottom contains the order entities. I would like to implement an “click action/listener” within the selection of an customer the content of the order table will be re-/loaded.

How can I implement this kind of Listener or Action?

Is following way recommened and how to trigger the second datasource to reload the nested content?

@Override
public void init(Map<String, Object> params) {
    ((LookupSelectionChangeNotifier) mainTable)
            .addLookupValueChangeListener(new LookupSelectionChangeListener() {
                @Override
                public void lookupValueChanged(LookupSelectionChangeEvent event) {
                    Customer singleSelected = mainTable.getSingleSelected();
                    // fill second table
                }
            });
}

Hi,

You can refer to another data source within JPQL query. So, in your case, I would recommend you to define your data sources as follows:

<dsContext>
    <collectionDatasource id="customersDs"
                          class="com.company.sales.entity.Customer"
                          view="_local">
        <query>
            <![CDATA[select e from sales$Customer e]]>
        </query>
    </collectionDatasource>
    <collectionDatasource id="ordersDs"
                          class="com.company.sales.entity.Order"
                          view="orderWithCustomer">
        <query>
            <![CDATA[select e from sales$Order e where e.customer.id = :ds$customersDs]]>
        </query>
    </collectionDatasource>
</dsContext>

Take notice of e.customer.id = :ds$customersDs. This means that order customer equals to a value from customersDs, i.e. to the selected row.

See Query Parameters for more details.

Regards,
Gleb

Hi,

thanks your solution is working!

The refresh behaviour of the order table has to be fixed, therefore I added a Refresh Button on top for the manual fix and call on the second datasource after each action refresh.

In my case, I don’t need to add manual refresh functionality. Could you check this project sales.zip (116.3 KB)