Migrating ValueCollectionDatasource to v7?

I have some valueCollectionDatasource objects declared on my Main Window (used for graphs in a dashboard). These are ad-hoc queries and don’t have a corresponding Entity or View to work from.

For example:

        <valueCollectionDatasource id="offerStatsDs">
                <![CDATA[select e.offercode, e.offerdesc, 
       sum(e.orders) as ordCount, 
       sum(e.totpurch) as totAmount
from rade$OfferStats e
where e.category = :component$txtCategory
and e.purchdate between :component$dateStart and :component$dateEnd
group by e.offercode, e.offerdesc
order by 1
                <property datatype="string"
                <property datatype="string"
                <property datatype="long"
                <property datatype="CurrencyDatatype"

How do I translate this to v7 and declare it in XML?

As an aside, losing the “:component$” option means I have to write more code (setParameter calls). It was so much easier before… :wink:

Since I now have to set the parameters in code, how do I reference the Data Loader in code when it doesn’t have a base entity to put in the type?

private CollectionLoader< ...what goes here... > offerStatsDl;

Use visual designer for prototyping screens. A typical definition of KeyValueCollectionContainer:

<keyValueCollection id="orderStatsDc">
    <loader id="orderStatsDl">
        <query><![CDATA[select sum(e.quantity * e.product.price) from sales_OrderLine e where e.order = :order ]]></query>
        <property name="total" datatype="decimal"/>

Use Code > Generate > Inject action (Alt+Insert or Cmd+N) to inject references to components in screen controller. The loader from above is injected as follows:

private KeyValueCollectionLoader orderStatsDl;

@Subscribe(id = "ordersDc", target = Target.DATA_CONTAINER)
private void onOrdersDcItemChange(InstanceContainer.ItemChangeEvent<Order> event) {
    orderStatsDl.setParameter("order", event.getItem());

This is a valid point. There is an example of how to implement declarative binding of parameters on the project level, but we’ll think how to provide it in the framework.


Thanks. Can I suggest you add a KeyValueCollection XML example to the docs? I do see the objects mentioned but no indication on how to use them.

I have been using Alt-Insert in the java code, but I have to start using it more on the XML side too.

IntelliJ starts suggesting you possible elements as soon as you open a bracket in code: <.
But you are right, the docs should have it too.