Announcement

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

    DateItem returns either Date or String object

    I have a problem when using a DateItem or DateTimeItem in the new ListGridEditorCustomizer.
    Depending on the locale editComplete() or editorExit() gets 2 different object classes: using en_US I get a Date object and using de_DE I get a string.

    Following is a test case (based on the sample for ListGridEditorCustomizer) which demonstrates this:
    Code:
    package selectrow.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.types.ListGridEditEvent;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.form.fields.DateItem;
    import com.smartgwt.client.widgets.form.fields.FormItem;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.ListGridEditorContext;
    import com.smartgwt.client.widgets.grid.ListGridEditorCustomizer;
    import com.smartgwt.client.widgets.grid.ListGridField;
    import com.smartgwt.client.widgets.grid.ListGridRecord;
    import com.smartgwt.client.widgets.grid.events.EditCompleteEvent;
    import com.smartgwt.client.widgets.grid.events.EditCompleteHandler;
    import java.util.Date;
    
    public class MainEntryPoint implements EntryPoint {
        @Override
        public void onModuleLoad() {
            final ListGrid countryGrid = new ListGrid();
            countryGrid.setWidth(300);
            countryGrid.setHeight(340);
            countryGrid.setShowAllRecords(true);
    
            ListGridField nameField = new ListGridField("name", "Name", 120);
            nameField.setCanEdit(false);
    
            ListGridField valueField = new ListGridField("value", "Value Field", 170);
    
            countryGrid.setFields(nameField, valueField);
            countryGrid.addEditCompleteHandler(new EditCompleteHandler() {
               @Override
               public void onEditComplete(EditCompleteEvent event) {
                   StringBuilder result = new StringBuilder();
                   for (Object newValue : event.getNewValues().values())
                       result.append(newValue.getClass().getName()).append(", ");
                   SC.say("Date class: " + result.toString());
               }
            });
    
            countryGrid.setData(getData());
            countryGrid.setEditorCustomizer(new ListGridEditorCustomizer() {
                @Override
                public FormItem getEditor(ListGridEditorContext context) {
                    ListGridField field = context.getEditField();
                    if (field.getName().equals("value")) {
                        NameValueRecord record = (NameValueRecord) context.getEditedRecord();
                        int id = record.getID();
                        switch (id) {
                            case 3:
                                DateItem result = new DateItem();
                                result.setUseTextField(true);
                                return result;
                            default:
                                return context.getDefaultProperties();
                        }
                    }
                    return context.getDefaultProperties();
                }
            });
    
            countryGrid.setCanEdit(true);
            countryGrid.setEditEvent(ListGridEditEvent.CLICK);
            countryGrid.setEditByCell(false);
    
            countryGrid.draw();
        }
    
        private ListGridRecord[] getData() {
            return new ListGridRecord[]{
                    new NameValueRecord(1, "String Editor", "some string"),
                    new NameValueRecord(2, "Password Editor", "donkeykong"),
                    new NameValueRecord(3, "Date Editor", new Date()),
                    new NameValueRecord(4, "Boolean Editor", Boolean.FALSE),
                    new NameValueRecord(5, "Spinner Int Editor", 5),
                    new NameValueRecord(6, "SelectItem Editor", "Dog"),
                    new NameValueRecord(7, "Slider Editor", 7)
            };
        }
        public static class NameValueRecord extends ListGridRecord {
            public NameValueRecord(int id, String name, Object value) {
                setID(id);
                setName(name);
                setValue(value);
            }
            public final void setID(int id) {
                setAttribute("ID", id);
            }
            public int getID() {
                return getAttributeAsInt("ID");
            }
            public final void setValue(Object value) {
                setAttribute("value", value);
            }
            public Object getValue() {
                return getAttributeAsObject("value");
            }
            public final void setName(String name) {
                setAttribute("name", name);
            }
            public String getName() {
                return getAttribute("name");
            }
        }
    }
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.7.0//EN" "http://google-web-toolkit.googlecode.com/svn/tags/1.7.0/distro-source/core/src/gwt-module.dtd">
    
    <module rename-to='selectrow'>
        <inherits name="com.google.gwt.i18n.I18N"/>
        <inherits name="com.google.gwt.user.User"/>
        <inherits name="com.google.gwt.core.Core"/>
        <inherits name="com.google.gwt.user.History"/>
        <inherits name="com.smartgwt.SmartGwtNoScript"/>
        <inherits name="com.smartgwt.tools.SmartGwtTools"/>
        <inherits name="com.smartclient.theme.graphite.Graphite"/>
        <extend-property name="locale" values="de_DE"/>
        <extend-property name="locale" values="en_US"/>
        <set-property-fallback name="locale" value="de_DE"/>
        <entry-point class="selectrow.client.MainEntryPoint"/>
    </module>
    Compile and run this sample, edit the date, finish editing and you get a message, telling you the class of the 'newValue'.
    Run it with locale en_US and you get a Date.
    Run it with locale de_DE and you get a String.

    This doesn't make sense to me...

    I'm using SmartGWT 2.5 and GWT 2.3

    #2
    What browser(s) does this occur on? Hosted only, or also in compiled mode?

    Can you post the contents of the de_DE locale file you are using - even if you think it's the same as the SDK default we need to see it.

    Comment


      #3
      It happens in hosted and development mode. What do you mean by "compiled" mode?

      It happens on FF6 and IE9 (I haven't tried any others yet...)

      I'm not using any de_DE locale file apart from what's in the package.
      Were would I find what you want?

      Comment

      Working...
      X