What is the correct way to use Value Datasources? Any simple demo project would be very helpful.

Hi there,
I am excited seeing “Value Datasources” is added in ver 6.4.0:
https://doc.cuba-platform.com/manual-6.4/value_datasources.html
However, it can not be recognized in XML declaration file (sales.xml) with error “Element valueCollectionDatasource is not allowed here” shown in IntelliJ:


<dsContext>
        <valueCollectionDatasource id="salesAggregatorDs">
            <query>
                <![CDATA[select o.orderDate, sum(o.amount) from posportal$Order o group by o.orderDate]]>
            </query>
            <properties>
                <property datatype="dateTime"
                          name="orderDate"/>
                <property datatype="decimal"
                          name="sum"/>
            </properties>
        </valueCollectionDatasource>
    </dsContext>

salesAggregatorDs is the dataSource of a SerialChart. I wanted to add items to the SerialChart from an query to Order table.
Furthermore, in screen controller sales.java, I have problem to @inject this Datasource:


 @Inject
    private CollectionDatasource<KeyValueEntity, Object> salesAggregatorDs;

The error is:
“Type parameter ‘com.haulmont.cuba.core.entity.KeyValueEntity’ is not within its bound; should implement 'com.haulmont.cuba.core.entity.Entity<java.lang.Object>”

Could you provide a sample demo project of how to use Value Datasources(especially used as a Datasource of a SerialChart), or direct me to the URL if you already have one?

Thank you,
-Mike

(Re-post, formatted)
Hi there,

I am excited seeing “Value Datasources” is added in ver 6.4.0:
https://doc.cuba-platform.com/manual-6.4/value_datasources.html

However, it can not be recognized in XML declaration file (sales.xml) with
error “Element valueCollectionDatasource is not allowed here” shown in IntelliJ:


<dsContext> 
   <valueCollectionDatasource id="salesAggregatorDs"> 
      <query> 
         <![CDATA[select o.orderDate, sum(o.amount) from posportal$Order o group by o.orderDate]]> 
      </query> 
      <properties> 
         <property datatype="dateTime" name="orderDate"></property> 
         <property datatype="decimal" name="sum"></property> 
      </properties> 
   </valueCollectionDatasource> 
</dsContext>

salesAggregatorDs is the dataSource of a SerialChart. I wanted to add items to the SerialChart from
an query to Order table.

Furthermore, in screen controller sales.java, I have problem to @inject this Datasource:


@Inject private CollectionDatasource<KeyValueEntity, Object> salesAggregatorDs; 

The error is: “Type parameter ‘com.haulmont.cuba.core.entity.KeyValueEntity’ is not within its bound; should
implement 'com.haulmont.cuba.core.entity.Entity<java.lang.Object>”

Could you provide a sample demo project of how to use Value Datasources(especially used as a Datasource of
a SerialChart), or direct me to the URL if you already have one?

Thank you, -Mike

Sure. Check out this project: https://github.com/cuba-labs/demo-64-value-ds

This screen demonstrates a value datasource connected to a table and a chart.

It is really great. I tried the demo you sent and it works flawlessly!

However when it is used in my project, I still can not get rid of the error:


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Compile error begin  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
web:compileJava <path to project>\modules\web\src\cloud\pospro\posportal\web\screens\Sales.java:43: error: type argument KeyValueEntity is not within bounds of type-variable T
    private CollectionDatasource<KeyValueEntity, Object> salesAggregatorDs;
                                 ^
  where T,K are type-variables:
    T extends Entity<K> declared in interface CollectionDatasource
    K extends Object declared in interface CollectionDatasource
1 error
 FAILED
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Compile error end  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is where I @inject the Value Datasource salesAggregatorDs, which was declared in Sales.xml file.

My cuba studio (Registered):
Version 6.4.1

Looks like com.haulmont.cuba.core.entity.KeyValueEntity is inaccessible from web screen.

Any insights is appreciated!

-Mike

Update:
Sorry for my overlook that the “Platform version” was mistakenly chosen 6.3.5, in which Value Datasource was not introduced yet.

After selecting 6.4.1, valueCollectionDatasource shows up in the Type dropdown option, the @inject error goes away.

Thank you very much for the help,
-Mike