Hi Isomorphic,
please see the following testcase:
Setup:
SmartClient Version: v12.0p_2020-01-09/PowerEdition Deployment (built 2020-01-09)
BuiltInDS.java
BuiltInDS.html
animals.ds.xml
batchUpload.ds.xml
BatchUploadDMI.java
You can find Problem1 and Problem2 in BuiltInDS.java
Problem 1:
How can I put the fakeField "moreInformation" in the Response, so that it is also delivered to the client?
Please see my above trys.
TRY_NO.1:
I tried to put the "moreInformation","Y" to the dataMap by doing the following:
If You run the code, the log says null null. So I guess I always receive a new dataMap, am I right here?
So that doesnt work
TRY_NO.2:
with this code (obviously) the map holds the value afterwards. (See log)
But how do I get it back in the Response?
I tried:
and
but neither of both worked
TRY_NO.3:
i simply tried
Problem 2:
I would have prefered to work with
and then calling
But here is something wrong now I think. "records" is not null BUT if I call
on it, it throws an com.google.gwt.core.client.JavaScriptException.
Can You please give me some advice on how to get that field to the client within the transformResponse method?
Thanks in advance,
Kind Regards
please see the following testcase:
Setup:
SmartClient Version: v12.0p_2020-01-09/PowerEdition Deployment (built 2020-01-09)
BuiltInDS.java
Code:
package com.smartgwt.sample.client; import java.util.List; import java.util.Map; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.JavaScriptObject; import com.smartgwt.client.core.KeyIdentifier; import com.smartgwt.client.data.DSRequest; import com.smartgwt.client.data.DSResponse; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.data.Record; import com.smartgwt.client.data.RecordList; import com.smartgwt.client.data.ResponseTransformer; import com.smartgwt.client.types.PartialCommitOption; import com.smartgwt.client.util.JSOHelper; import com.smartgwt.client.util.Page; import com.smartgwt.client.util.PageKeyHandler; import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.BatchUploader; import com.smartgwt.client.widgets.grid.ListGridField; import com.smartgwt.client.widgets.grid.ListGridRecord; import com.smartgwt.client.widgets.layout.VStack; /** * Entry point classes define <code>onModuleLoad()</code>. */ public class BuiltInDS implements EntryPoint { /** * This is the entry point method. */ public void onModuleLoad() { KeyIdentifier debugKey = new KeyIdentifier(); debugKey.setCtrlKey(true); debugKey.setKeyName("D"); Page.registerKey(debugKey, new PageKeyHandler() { public void execute(String keyName) { SC.showConsole(); } }); VStack vStack = new VStack(); vStack.setLeft(175); vStack.setTop(75); vStack.setWidth("70%"); vStack.setMembersMargin(20); BatchUploader batchUploader = new BatchUploader(); batchUploader.setUploadDataSource(DataSource.get("animals")); batchUploader.setPartialCommit(PartialCommitOption.RETAIN); batchUploader.setUploadDelimiter(";"); ListGridField commonName = new ListGridField("commonName"); ListGridField scientificName = new ListGridField("scientificName"); ListGridField moreInformation = new ListGridField("moreInformation"); batchUploader.setGridFields(commonName, scientificName, moreInformation); batchUploader.draw(); DataSource.get("batchUpload", null, new ResponseTransformer() { @SuppressWarnings("unchecked") @Override protected void transformResponse(DSResponse response, DSRequest request, Object data) { // Problem 1: // TRY_NO.1 // Log "moreInformation" BEFORE SC.logWarn(((Map<String, Object>) ((List<Map<String, Object>>) response.getDataAsMap().get("gridRows")).get(0)) .get("moreInformation") != null ? ((Map<String, Object>) ((List<Map<String, Object>>) response.getDataAsMap().get("gridRows")).get(0)) .get("moreInformation").toString() : "null"); // Add value fo "moreInformation" ((Map<String, Object>) ((List<Map<String, Object>>) response.getDataAsMap().get("gridRows")).get(0)).put("moreInformation", "Y"); // Log "moreInformation" AFTER SC.logWarn(((Map<String, Object>) ((List<Map<String, Object>>) response.getDataAsMap().get("gridRows")).get(0)) .get("moreInformation") != null ? ((Map<String, Object>) ((List<Map<String, Object>>) response.getDataAsMap().get("gridRows")).get(0)) .get("moreInformation").toString() : "null"); // TRY_NO.2 List<Map<String, Object>> gridRows = (List<Map<String, Object>>) response.getDataAsMap().get("gridRows"); // Log "moreInformation" BEFORE SC.logWarn(gridRows.get(0).get("moreInformation") != null ? gridRows.get(0).get("moreInformation").toString() : "null"); // Add value fo "moreInformation" gridRows.get(0).put("moreInformation", "Y"); // Log "moreInformation" AFTER SC.logWarn(gridRows.get(0).get("moreInformation") != null ? gridRows.get(0).get("moreInformation").toString() : "null"); // Doesn't work response.setAttribute("gridRows", gridRows); // Doesn't work either JavaScriptObject jsoArray = JSOHelper.convertMapToJavascriptObject(gridRows.get(0)); Record[] recordsA = Record.convertToRecordArray(jsoArray); ListGridRecord[] lGrecords = new ListGridRecord[1]; lGrecords[0] = new ListGridRecord(recordsA[0].getJsObj()); response.setAttribute("operationType", "fetch"); response.setData(lGrecords); // Problem 2: // works RecordList records = response.getDataAsRecordList(); // EXCEPTION: com.google.gwt.core.client.JavaScriptException int length = response.getDataAsRecordList().getLength(); } }); } }
Code:
<!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <!-- --> <!-- Any title is fine --> <!-- --> <title>BuiltInDS</title> <!-- IMPORTANT : You must set the variable isomorphicDir to [MODULE_NAME]/sc/ so that the SmartGWT resource are correctly resolved --> <script> var isomorphicDir = "builtinds/sc/"; </script> <!-- --> <!-- This script loads your compiled module. --> <!-- If you add any GWT meta tags, they must --> <!-- be added before this line. --> <!-- --> <script type="text/javascript" language="javascript" src="builtinds/builtinds.nocache.js"></script> <!-- The following script is required if you're running (Super)DevMode and are using module definitions that contain <script> tags. Normally, this script is loaded automatically by builtinds.nocache.js above, but this isn't possible when (Super)DevMode is running. Note: it should not create any issue to always load it below (even if already loaded). --> <script type="text/javascript" language="javascript" src="builtinds/loadScriptTagFiles.js"></script> </head> <!-- --> <!-- The body can have arbitrary html, or --> <!-- you can leave the body empty if you want --> <!-- to create a completely dynamic UI. --> <!-- --> <body> <!--load the datasources--> <script src="builtinds/sc/DataSourceLoader?dataSource=supplyItem,animals,employees,batchUpload"></script> <!-- OPTIONAL: include this if you want history support --> <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe> </body> </html>
Code:
<DataSource ID="animals" serverType="sql" tableName="animals" testFileName="animals.data.xml" > <fields> <field name="commonName" title="Animal" type="text" > </field> <field name="scientificName" title="Scientific Name" type="text" primaryKey="true" required="true"/> <field name="lifeSpan" title="Life Span" type="integer"/> <field name="status" title="Endangered Status" type="text"> <valueMap> <value>Threatened</value> <value>Endangered</value> <value>Not Endangered</value> <value>Not currently listed</value> <value>May become threatened</value> <value>Protected</value> </valueMap> </field> <field name="diet" title="Diet" type="text"/> <field name="information" title="Interesting Facts" type="text" length="1000"/> <field name="moreInformation" customSelectExpression="1"/> <field name="picture" title="Picture" type="image" detail="true" imageURLPrefix="/isomorphic/system/reference/inlineExamples/tiles/images/"/> </fields> </DataSource>
batchUpload.ds.xml
Code:
<DataSource ID="batchUpload"> <operationBindings> <operationBinding operationType="add" operationId="upload" serverMethod="batchUpload"> <explanation>First do: boolean conversions, date conversions and list conversions. Then validate and upload data.</explanation> </operationBinding> </operationBindings> <serverObject ID="batchUpload" className="com.smartgwt.sample.server.listener.BatchUploadDMI" dropExtraFields="false"> <visibleMethods> <method name="batchUpload" /> <method name="wipeData" /> </visibleMethods> </serverObject> </DataSource>
Code:
package com.smartgwt.sample.server.listener; import java.util.Map; import com.isomorphic.datasource.DSRequest; import com.isomorphic.datasource.DSResponse; import com.isomorphic.tools.BatchUpload; public class BatchUploadDMI { public DSResponse batchUpload(DSRequest dsRequest) throws Exception { BatchUpload batchUpload = new BatchUpload(); // parse data and get the result Map DSResponse response = batchUpload.parseUploadData(dsRequest); Map<?, ?> respData = response.getDataMap(); // do not proceed to validation if parsing failed if (respData.containsKey("errorMessage")) return response; DSResponse validatedData = batchUpload.validateUploadData(response); return validatedData; } }
Problem 1:
How can I put the fakeField "moreInformation" in the Response, so that it is also delivered to the client?
Please see my above trys.
TRY_NO.1:
I tried to put the "moreInformation","Y" to the dataMap by doing the following:
Code:
((Map<String, Object>) ((List<Map<String, Object>>) response.getDataAsMap().get("gridRows")).get(0)).put("moreInformation", "Y");
So that doesnt work
TRY_NO.2:
Code:
List<Map<String, Object>> gridRows = (List<Map<String, Object>>) response.getDataAsMap().get("gridRows"); gridRows.get(0).put("moreInformation", "Y");
But how do I get it back in the Response?
I tried:
Code:
response.setAttribute("gridRows", gridRows);
Code:
JavaScriptObject jsoArray = JSOHelper.convertMapToJavascriptObject(gridRows.get(0)); Record[] recordsA = Record.convertToRecordArray(jsoArray); ListGridRecord[] lGrecords = new ListGridRecord[1]; lGrecords[0] = new ListGridRecord(recordsA[0].getJsObj()); response.setAttribute("operationType", "fetch"); response.setData(lGrecords);
TRY_NO.3:
i simply tried
Code:
for (Record r : response.getData()) { r.setAttribute("moreInformation", "Y"); }
Problem 2:
I would have prefered to work with
Code:
RecordList records = response.getDataAsRecordList();
Code:
setAttribute("moreInformation", "Y")
Code:
getLength()
Can You please give me some advice on how to get that field to the client within the transformResponse method?
Thanks in advance,
Kind Regards
Comment