Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    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.TOEUROPEANSHORTDATE);
    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(Native Method)
    at com.smartgwt.client.widgets.BaseWidget.getOrCreateJsObj(BaseWidget.java:280)
    at com.smartgwt.client.widgets.Canvas.addChild(Native Method)
    at awd.plm.gwt.document.client.DataPackage.createComponents(DataPackage.java:98)
    at awd.plm.gwt.document.client.DataPackage.onModuleLoad(DataPackage.java:41)

    How should I effect the rendering of widgets in a data source?

    #2
    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.

    Comment


      #3
      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

      Comment


        #4
        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;
            }
        });

        Comment


          #5
          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

          Comment


            #6
            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"));

            Comment

            Working...
            X