Hello,
I have a custom operation type that I use to handle adds and removals. I am having trouble with the response data. Since I am using a custom operation, I use the `
addRelatedUpdate` method to handle updating all databound grids. To handle the add, I simply call a fetch after executing the dsRequest with the related criteria.
For remove, I setAllowMultiUpdate(true) and set the criteria for both composite keys (we pass in a list for both using InSet). We don't get any data returned when performing this. The data is removed correctly BUT the databound grids related are not updating.
We tried this to send back data in hopes to update the databound grids but without success.
Here is my code:
I have a custom operation type that I use to handle adds and removals. I am having trouble with the response data. Since I am using a custom operation, I use the `
addRelatedUpdate` method to handle updating all databound grids. To handle the add, I simply call a fetch after executing the dsRequest with the related criteria.
For remove, I setAllowMultiUpdate(true) and set the criteria for both composite keys (we pass in a list for both using InSet). We don't get any data returned when performing this. The data is removed correctly BUT the databound grids related are not updating.
We tried this to send back data in hopes to update the databound grids but without success.
Here is my code:
Code:
@Override public DSResponse addRemoveOperation(final DSRequest dsRequest, final RPCManager rpcManager) throws ApplicationException { try { final Map<String, Object> values = dsRequest.getValues(); final List<Long> key1Ids = (List<Long>) values.get(KEY_1_IDS); final List<Long> key2Ids = (List<Long>) values.get(KEY_2_IDS); final String operationType = (String) values.get(OPERATION); final DSResponse response = new DSResponse(); if ((key1Ids!= null && !key1Ids.isEmpty()) && (key2Ids!= null && !key2Ids.isEmpty())) { if (operationType.equalsIgnoreCase(DataSource.OP_ADD)) { for (final long key1Id: key1Ids) { final Map<String, Object> keyMap = new HashMap<>(); keyMap.put(KEY_1_ID, key1Id); for (final Long key2Id: key2Ids) { keyMap.put(KEY_2_ID, key2Id); response.addRelatedUpdate( new DSRequest(DATASOURCE, DataSource.OP_ADD, rpcManager).setValues(keyMap).execute()); } } } else { final DSRequest deleteDSRequest = new DSRequest(DATASOURCE, DataSource.OP_REMOVE, rpcManager); deleteDSRequest.setAllowMultiUpdate(true); deleteDSRequest.addToCriteria(KEY_1_ID, DefaultOperators.InSet, key1Ids); deleteDSRequest.addToCriteria(KEY_s_ID, DefaultOperators.InSet, key2Ids); response.addRelatedUpdate(deleteDSRequest.execute()); } } return response; } catch (final Exception e) { throw new ApplicationException(e, SmartGWTStatusCode.STATUS_FAILURE); } } @Override public DSResponse add(final DSRequest dsRequest, final RPCManager rpcManager) throws ApplicationException { try { dsRequest.execute(); final AdvancedCriteria criteria = new AdvancedCriteria(DefaultOperators.And, new SimpleCriterion(KEY_1_ID, DefaultOperators.Equals, dsRequest.getValues().get(KEY_1_ID)), new SimpleCriterion(KEY_2_ID, DefaultOperators.Equals, dsRequest.getValues().get(KEY_2_ID))); return DSUtil.fetch(DATASOURCE, rpcManager, criteria).setOperationType(DataSource.OP_ADD); // this is a basic fetch method } catch (final Exception e) { throw new ApplicationException(e, SmartGWTStatusCode.STATUS_FAILURE); } } @Override public DSResponse remove(final DSRequest dsRequest, final RPCManager rpcManager) throws ApplicationException { try { final DSRequest request = new DSRequest(DATASOURCE, DataSource.OP_FETCH, rpcManager); request.setCriteria(dsRequest.getAdvancedCriteria()); final List<String> outputs = new ArrayList<>(); outputs.add(KEY_1_ID); outputs.add(KEY_2_ID); request.setOutputs(outputs); final DSResponse response = request.execute(); return dsRequest.execute().setData(response.getData()); } catch (final Exception e) { throw new ApplicationException(e, SmartGWTStatusCode.STATUS_FAILURE); } }
Comment