|
#1
|
|||
|
|||
|
Hi Isomorphic,
I just started using SmartGWT Server today and am impressed once more! My usecase was: on Buttonclick add a record to a DS, get the new (sequence-generated) ID and set this ID in some FK-column of another DS. I did this with stacked DSCallBacks first, which worked, but felt wrong as the data is transferred to the client and back to the server. Also, I couldn't get SQL-Transaction to work with this. Doing it the right way was some research, but now it works. For everyone interested here some pointers: http://forums.smartclient.com/showthread.php?t=14488 http://www.smartclient.com/smartgwte..._specific_data http://www.smartclient.com/smartgwtee/showcase/#dmi (http://www.smartclient.com/smartgwte...validation_dmi) Operation Bindings, Data Integration, Smart GWT Server Framework chapters in Quick Start Guide. http://www.smartclient.com/smartgwte...DSRequest.html http://www.smartclient.com/smartgwte...SResponse.html For me, following code worked. Having the possibility to interfere before and or after some DS-operation is great! Clientcode: Code:
DSRequest requestProperties = new DSRequest();
requestProperties.setOperationId("addFromKind");
guestDS.addData(r,null,requestProperties);
Code:
<operationBinding operationType="add" operationId="addFromKind"> <serverObject lookupStyle="new" className="com.acme.server.worker.AddGuest" methodName="addGuest"/> <values fieldName="MODIFIED_AT" value="$currentDate" /> </operationBinding> Code:
public class AddGuest {
public DSResponse addGuest(DSRequest dsRequest, HttpServletRequest servletRequest) throws Exception {
SQLTransaction.startTransaction(dsRequest.getRPCManager());
DSResponse guestResponse = dsRequest.execute();
if (guestResponse.getStatus() == DSResponse.STATUS_SUCCESS) {
// Get new ID
BigDecimal newGuestID = (BigDecimal) guestResponse.getDataField("ID");
// Prepare Update for T_KIND
DSRequest updateKindRequest = new DSRequest("T_KIND", "update");
updateKindRequest.setCriteria("ID", dsRequest.getFieldValue("KIND_ID"));
Map<String, String> m = new HashMap<String, String>();
m.put("GUEST_ID", newGuestID.toString());
updateKindRequest.setValues(m);
updateKindRequest.setRPCManager(dsRequest.getRPCManager());
DSResponse kindResponse = updateKindRequest.execute();
guestResponse.addRelatedUpdate(kindResponse);
SQLTransaction.commitTransaction(dsRequest.getRPCManager());
} else {
SQLTransaction.rollbackTransaction(dsRequest.getRPCManager());
guestResponse.setFailure();
}
SQLTransaction.endTransaction(dsRequest.getRPCManager());
return guestResponse;
}
};
I for myself have only one question left. I send 1 request and change 2 rows in different tables with this (=2 DSResponses). Is the way I do the Chaining correct (guestResponse.addRelatedUpdate has no Javadoc). Thanks & HF using SmartGWT, Blama |
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Download a File error | RHill | Technical Q&A | 12 | 5th Mar 2012 10:07 |
| JPADataSource - transaction problem when using queueing | dejan | Smart GWT Technical Q&A | 7 | 13th Feb 2012 13:22 |
| JPADataSource and ManyToMany relationship | dejan | Smart GWT Technical Q&A | 8 | 9th Feb 2012 08:27 |
| Filter on foreign table | valbosoft | Smart GWT Technical Q&A | 22 | 4th Jan 2012 12:50 |
| java.lang.NoClassDefFoundError: com/smartgwt/client/data/DSCallback on server side | maksymg | Smart GWT Technical Q&A | 1 | 6th Oct 2011 16:30 |