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:
DS operation binding:
ServerCode:
Perhaps this posts helps some users to get started with the server framework.
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
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