Calculated field in DataSource

Hi

I’m new into this matter..

I have a datasource with some fields and I defined a fetch operation which is correctly called

<DataSource
ID=“item”
serverType=“sql”
tableName=“item”
>
<fields>
<field name=“id” title=“ID” width=“32” type=“integer” primaryKey=“true” required=“true”/>
<field name=“marke” title=“Marke” type=“text” required=“true”/>
<field name=“typ” title=“Typ” type=“text”/>
</fields>

<operationBindings>
<operationBinding operationType=“fetch”>
<serverObject className=“com.smartgwt.sample.server.FahrzeugDMI” />
<serverMethod>calcPrice</serverMethod>
</operationBinding>
</operationBindings>
</DataSource>

In my Server Routine I would like to add a field which is also sent to the client and can be accessed to show in a Grid.

public DSResponse calcPrice(DSRequest dsRequest, HttpServletRequest servletRequest)
throws Exception
{
DSResponse resp = dsRequest.execute();
List<Map> list = resp.getRecords();
for (Map item : list) {
item.put(“price”, getCalculatedPrice()); // ???
}
return resp;
}

But this to work.
Have you got an example how this should be done?

Thank you
Pius

That’s the right approach, but having modified the data, be sure to call setData() with it. Also, you want to declare the field in your DataSource, so that we know it’s type and title and so forth.

Hi,

I use the same approach like pius, but still have some problems.

I use a DataSource to access a oracleDB and added a operationBinding to perform serverside calculations with the data i get in the response. The results should be added as new field.

However, i use setData() (suggested in the QuickstartGuide) to write the changed data back to the response but it never shows up in the client (here a ListGrid), only the fields defined in the DataSource can be accessed.
If I try to add a name for the calculated field to the DataSource i get an exception from SmartGwt because the field is not present in the database (ORA-00904).

Is there any way to define the DataSource in way that the calculated field can be accessed but prevent the DataSource from trying to fetch a field that is not present in the database? Or is there another way to get access to the calculated field?

Same Issue

Hi,

I’m having the same issue as Kanaan, is there a example of a server side calculated field on a DB backed datasource?