I'm using SmartGwt 2.5p with RTM and having a problem with ListGrid updates on my form.
When the form loads and does its initial load everything is fine, but when I later push new records to it I get the warning about the missing key field.
I have verified on the client side that the key field ('uid') is being received from the server and that it is being copied from the incoming data to the new Record.
Here's the code that copies the JSO data to the Record. It's based on the one example in the Messaging package.
Here's what I get in the Development Mode log:
here's the datasource definition:
Does this sound familiar? As far as I can tell there is a 'uid' attribute present when I pass the record to updateCaches().
When the form loads and does its initial load everything is fine, but when I later push new records to it I get the warning about the missing key field.
I have verified on the client side that the key field ('uid') is being received from the server and that it is being copied from the incoming data to the new Record.
Here's the code that copies the JSO data to the Record. It's based on the one example in the Messaging package.
Code:
public void updateRecords(final NavListGrid aGrid, final Object data) { try { @SuppressWarnings("unchecked") final List<LinkedHashMap<?, ?>> callsData = (List<LinkedHashMap<?, ?>>) JSOHelper.convertToJava((JavaScriptObject) data); final List<Record> newRecords = new ArrayList<Record>(); for (final LinkedHashMap<?, ?> recordData : callsData) { Record record; /* * Get the record we'll be loading */ final Integer uid = (Integer) recordData.get("uid"); if (uid == null) { SC.logWarn("null uid!"); record = null; } else { record = aGrid.getDataAsRecordList().find("uid", uid); } if (record == null) { record = new Record(); record.setAttribute("uid", uid); } /* * Go through each of the expected fields and set the corresponding attribute in the Record */ for (final ListGridField field : aGrid.getFields()) { final Object fieldValue = recordData.get(field.getName()); String msg = "---Field " + field.getName() + ", value " + fieldValue; if (fieldValue != null) { msg += ", class " + fieldValue.getClass().getName(); } SC.logWarn(msg); record.setAttribute(field.getName(), fieldValue); } newRecords.add(record); SC.logWarn("new record has uid " + record.getAttribute("uid")); } final DSResponse dsResponse = new DSResponse(); dsResponse.setData(newRecords.toArray(new Record[newRecords.size()])); final DSRequest dsRequest = new DSRequest(); dsRequest.setContentType("text/html; charset=UTF-8"); dsRequest.setOperationType(DSOperationType.UPDATE); aGrid.getDataSource().updateCaches(dsResponse, dsRequest); } catch (final Exception e) { e.printStackTrace(); SC.say(e.toString()); } }
Code:
[ERROR] [strategy] - 00:21:24.249:WARN:Log:---Field uid, value 68, class java.lang.Integer [ERROR] [strategy] - 00:21:24.253:WARN:Log:---Field timeStamp, value 1338524484207, class java.lang.String [ERROR] [strategy] - 00:21:24.264:WARN:Log:---Field level, value DEBUG, class java.lang.String [ERROR] [strategy] - 00:21:24.267:WARN:Log:---Field loggerName, value com.integral.strategy.server.datasource.GeneralDataSource, class java.lang.String [ERROR] [strategy] - 00:21:24.271:WARN:Log:---Field message, value executeFetch, LogFile, start 0, end -1, class java.lang.String [ERROR] [strategy] - 00:21:24.273:WARN:Log:new record has uid 68 [ERROR] [strategy] - 00:21:24.290:WARN:Log:findByKeys: passed record does not have a value for key field 'uid'
Code:
<DataSource ID="logDS" schemaBean="com.integral.strategy.server.log.LogRecord" serverConstructor="com.integral.strategy.server.log.LogDataSource" dropExtraFields="true" sendExtraFields="false" > <fields> <field primaryKey="true" name="uid" hidden="false" type="integer" /> <field name="level" type="text" /> <field name="loggerName" type="text" /> <field name="message" type="text" /> <field name="timeStamp" type="text" /> </fields> </DataSource>