Go Back   SmartClient Forums > Smart GWT Technical Q&A
Register Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 11th Dec 2008, 12:57
bizhub bizhub is offline
Registered Developer
 
Join Date: Nov 2008
Posts: 27
Default Customer date format in datasource definition

G'day,

I am trying to set my data source to use a different date format in a date field.

DataSourceDateField documentDateField = new DataSourceDateField("documentDate", "Date", 10, false);
DateItem dateItem = new DateItem();
dateItem.setName("documentDate");
dateItem.setTitle("Date");
dateItem.setRequired(false);
dateItem.setDisplayFormat(DateDisplayFormat.TOEURO PEANSHORTDATE);
documentDateField.setEditorType(dateItem);
documentDateField.setValueXPath("domain.DataPkgRec /documentDate");

I get the following error if I call documentDateField.setEditorType(dateItem), but if I comment this out, all runs well.

[ERROR] Unable to load module entry point class awd.plm.gwt.document.client.DataPackage (see associated exception for details)
com.google.gwt.core.client.JavaScriptException: (TypeError): Object expected
number: -2146823281
description: Object expected
at com.smartgwt.client.util.JSOHelper.setAttribute(Na tive Method)
at com.smartgwt.client.widgets.BaseWidget.getOrCreate JsObj(BaseWidget.java:280)
at com.smartgwt.client.widgets.Canvas.addChild(Native Method)
at awd.plm.gwt.document.client.DataPackage.createComp onents(DataPackage.java:98)
at awd.plm.gwt.document.client.DataPackage.onModuleLo ad(DataPackage.java:41)

How should I effect the rendering of widgets in a data source?
Reply With Quote
  #2  
Old 11th Dec 2008, 20:31
Isomorphic Isomorphic is offline
Administrator
 
Join Date: May 2006
Posts: 13,637
Default

There are some APIs missing in SmartGWT relative to SmartClient that allow you to set the default input and display formats for Dates system-wide. They'll be added soon in a nightly. In the meantime, use listGrid.dateFormatter for grids and use DateItem.setDisplayFormat(), but use it for each field.
Reply With Quote
  #3  
Old 8th Jan 2009, 22:27
mivola mivola is offline
Registered Developer
 
Join Date: Jan 2009
Posts: 17
Default

Quote:
Originally Posted by Isomorphic
There are some APIs missing in SmartGWT relative to SmartClient that allow you to set the default input and display formats for Dates system-wide. They'll be added soon in a nightly. In the meantime, use listGrid.dateFormatter for grids and use DateItem.setDisplayFormat(), but use it for each field.

The "listGrid.dateFormatter" works fine, but what if I would like to use a format that is not provided by DateFormatter (eg "dd.MM.YYYY")? Can I extend the DateFormatter?

Thanks
Michael
Reply With Quote
  #4  
Old 12th May 2009, 11:02
smartgwt.dev smartgwt.dev is offline
Registered Developer
 
Join Date: Nov 2008
Posts: 875
Default

From here :

The following static utility methods have been added to com.smartgwt.client.util.DateUtil along with sample code in the javadocs. These methods allow you to set date formats centrally and will affect the entire application.

setNormalDateDisplayFormat(DateDisplayFormat format)
setNormalDateDisplayFormatter(DateDisplayFormatter formatter)

setShortDateDisplayFormat(DateDisplayFormat format)
setShortDateDisplayFormatter(DateDisplayFormatter formatter)

setDateInputFormatter(DateInputFormatter formatter)

Example usage of setShortDateDisplayFormatter:

Code:
DateUtil.setShortDateDisplayFormatter(new DateDisplayFormatter() { public String format(Date date) { if(date == null) return null; //you'll probably want to create the DateTimeFormat outside this method. //here for illustration purposes DateTimeFormat dateFormatter = DateTimeFormat.getFormat("MMM d, yyyy"); String format = dateFormatter.format(date); return format; } });
Reply With Quote
  #5  
Old 11th Dec 2009, 07:54
jay.l.fisher jay.l.fisher is offline
Registered Developer
 
Join Date: Oct 2009
Posts: 352
Default

DateUtil doesn't seem to expose any helper methods for formatting dates in code. I have a TileGrid where I've overridden getTileHTML so I can format the data fields into a string of HTML. My Date field shows up in the super long format; "Mon May 22 2010 00:00:00 GMT-6 (CST)" and I'd like to format it as just "May 22, 2010". I tried to use java SimpleDateFormat but GWT doesn't support java.text.

Is there a recommended method for date formatting in SmartGWT?

Using GWT 2.0 and SmartGWT EE 1.2.2
Reply With Quote
  #6  
Old 11th Dec 2009, 07:59
jay.l.fisher jay.l.fisher is offline
Registered Developer
 
Join Date: Oct 2009
Posts: 352
Default

I was just looking in the wrong place.

import com.google.gwt.i18n.client.DateTimeFormat;

DateTimeFormat dateFormatter = DateTimeFormat.getFormat("MMM d, yyyy");
dateFormatter.format(getAttributeAsDate("OrderDate "));
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search


©2006 Isomorphic Software   ·   Terms of use