Note that there are some explanatory texts on larger screens.

plurals
  1. POOutput datetime value to StaticTextField in SmartGWT
    primarykey
    data
    text
    <p>I have a field in my dataset defined as:</p> <pre><code>DataSourceDateTimeField dateField = new DataSourceDateTimeField("date"); </code></pre> <p>and a <code>StaticTextItem</code> in <code>DynamicForm</code> defined as</p> <pre><code>StaticTextItem dateItem = new StaticTextItem("date", "Date"); </code></pre> <p>I played a lot with different combinations of <code>setDateFormatter</code>, but datetime values are still rendered as something like <code>2011-08-23T20:00:00</code> (datasource receives it in json as a <code>yyyy-MM-dd'T'HH:mm:ss.SSSZ</code> field).</p> <p>Is there some easy way to output datetime values to <code>StaticTextItem</code>? I assume using <code>DynamicForm.fetchData()</code>.</p> <hr> <p>UPD1. Data example.</p> <p>Table row in PgSQL:</p> <pre><code>1 | "2011-09-29 12:10:05.010276+04" | "Europe" </code></pre> <p>Data sent by REST service:</p> <pre><code>{ "location":"Europe", "id":1, "date":"2011-09-29T08:10:05.010+0000" } </code></pre> <p>Data fetched by SGWT from REST service (I dumped it with <code>JSON.encode(XMLTools.selectObjects(data, "/").getJavaScriptObject())</code> in my implementation of <code>transformResponse()</code>) :</p> <pre><code>{ "location":"Europe", "id":1, "date":"2011-09-29T08:10:05" } </code></pre> <p>Value as rendered in StaticTextField:</p> <pre><code>2011-09-29T08:10:05 </code></pre> <p>So datetime values returned by server seem to conform the <a href="http://www.w3schools.com/schema/schema_dtypes_date.asp" rel="nofollow">standard</a> and also I have no warnings in Developer Console.</p> <hr> <p>UPD2. May be I'm doing something wrong in my <code>transformResponse()</code> ? </p> <pre><code>protected void transformResponse(DSResponse response, DSRequest request, Object data) { String json = JSON.encode(XMLTools.selectObjects(data, "/").getJavaScriptObject()); SC.logWarn("Response received"); SC.logWarn(json); Record[] records = jsonToRecords(json); //safe HTML text values for (Record rec: records) { for (DataSourceField field: getFields()) { if (field.getType() == FieldType.TEXT) { String textVal = rec.getAttribute(field.getName()); if (textVal != null) { textVal = SafeHtmlUtils.htmlEscape(textVal); } rec.setAttribute(field.getName(), textVal); } } } response.setData(records); response.setStartRow(0); response.setEndRow(records.length); response.setTotalRows(records.length); } /** * Converts JS-array into SmartGWT records */ public static native ListGridRecord[] jsonToRecords(String jsonString) /*-{ var json = eval(jsonString); return @com.smartgwt.client.widgets.grid.ListGrid::convertToListGridRecordArray(Lcom/google/gwt/core/client/JavaScriptObject;)(json); }-*/; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload