Hello, using SGWT PRO 3.0p
I have an add DMI method that must do an update operation in the case a row already exists, like so.
the operationbinding making this happen:
When the update is required because a row already exists, I use setFieldValue (also tried setValues) on the DSRequest to set all the fields. Somehow it is not picked up, getting the:
I triple checked the values, and they are present.
Also i tried the approach where I put a complete map in using update.setValues(myMap)
The fields being added are all actual fields from the datasource.
Am I doing something wrong?
I have an add DMI method that must do an update operation in the case a row already exists, like so.
Code:
public DSResponse add(DSRequest req) throws Exception{
//if already exists, do an update with the amount being added.
DSRequest fetch = new DSRequest("Order__orderedDishes_Dish", "fetch");
fetch.setRPCManager(req.getRPCManager());
Map<String,Object> crit = new HashMap<String,Object>();
crit.put("Package_id", req.getFieldValue("Package_id"));
crit.put("Order__id", req.getFieldValue("Order__id"));
crit.put("Dish_id", req.getFieldValue("Dish_id"));
fetch.setCriteria(crit);
DSResponse resp = fetch.execute();
List data = resp.getDataList();
if(data == null || data.size() == 0){
logger.debug("doing an add, since there was no row found yet.");
return req.execute();
}
else {// do an update instead
logger.debug("doing an update instead of an add");
Map rec = (Map) data.get(0);
Integer orderedDishId = (Integer) rec.get("orderedDishes_id");
DSRequest update = new DSRequest("Order__orderedDishes_Dish", "update");
update.setRPCManager(req.getRPCManager());
Map values = req.getValues();
update.setFieldValue("amountOrdered", ((Long)values.get("amountOrdered")+(Long) req.getFieldValue("amountOrdered")));
update.setFieldValue("orderedDishes_id", orderedDishId);
update.setFieldValue("Package_id", req.getFieldValue("Package_id"));
update.setFieldValue("Dish_id", req.getFieldValue("Dish_id"));
update.setFieldValue("Order__id", req.getFieldValue("Order__id"));
return update.execute();
}
}
Code:
<operationBinding requiresRole="CAN_CREATE_ORDER__ORDEREDDISHES_DISH" requiresAuthentication="true" operationType="add" operationId="UpdateIfAlreadyExists">
<cacheSyncOperation>JoinOnPkg</cacheSyncOperation>
<serverObject className="nl.sytematic.projects.CateringSoftware.server.custom.dmi.Order__orderedDishes_Dish_CustomDMI"/>
</operationBinding>
When the update is required because a row already exists, I use setFieldValue (also tried setValues) on the DSRequest to set all the fields. Somehow it is not picked up, getting the:
Code:
=== 2012-04-05 17:23:41,878 [l0-0] WARN SQLDataSource - [builtinApplication.null] Insert, update or replace operation requires non-empty values; check submitted values parameter
Also i tried the approach where I put a complete map in using update.setValues(myMap)
The fields being added are all actual fields from the datasource.
Am I doing something wrong?
Comment