Announcement

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

    Date format encoding bug with DateItem using text field

    Hi,

    When I use a DateItem with setUseTextField(Boolean.TRUE) the date encoding in JSON isn't used and the data is send as displayed instead of the JSON date encoding preference. The same works correctly if you don't use the setUseTextField.

    You can easily reproduce with that and then look at the Developer console to see that the date isn't send in the default JSON date format.

    Code:
        public void onModuleLoad() {
            RestDataSource rds=new RestDataSource();
            rds.setDataFormat(DSDataFormat.JSON);        
            DataSourceDateField dfield=new DataSourceDateField("date");
            rds.setFields(dfield);
    
            final DynamicForm dm=new DynamicForm();
            dm.setDataSource(rds);
            DateItem date=new DateItem("date","Date");
            date.setUseTextField(Boolean.TRUE);
            ButtonItem send=new ButtonItem("send");
            send.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    dm.saveData();
                }
            });
            dm.setFields(date,send);
            dm.setHeight100();
            dm.setWidth100();
    
            RootPanel.get().add(dm);
    The same removing the useTextField works correctly.

    Can I submit this as a bug?

    Browser: Ie8 but it's not browser dependent
    SmartGWT 2.3 current trunk version

    #2
    I had a related issue when setting a date object to be read only via canEdit="false". Basically once you do something that causes your date to be displayed in anything but a DateField then it is not a date anymore and you are on your own to handle the contained text as a date and convert or format as you require.

    You may be able to use the overloaded version of saveData
    public void saveData(DSCallback callback,
    DSRequest requestProperties)

    and maniipulate your date as "displayed text" back into the appropriate format using the DSRequest which should give you access to the Record object. This is an untested guess so good luck.

    Comment


      #3
      Neither the original post nor the advice is making much sense to us..

      The original post does not try to set a date format at all. JSON and how the date is represented on the wire has nothing to do with how it's displayed to the user.

      As to the second post, if the field is not editable, a StaticTextItem is used. But this formItem respects both system-wide date format settings and settings on the DataSourceField or SimpleType. And how the date is displayed again is not related to how it's saved - it's shown to the user as a String, but it's a Date instance and is not changed by being displayed.

      Comment


        #4
        Code:
        The original post does not try to set a date format at all. 
        JSON and how the date is represented on the wire has nothing 
        to do with how it's displayed to the user.
        This is what my bug is about. The date is represented on the wire in the same way that is displayed when you use UseTextField.

        If you run and look at the developer console you will see that data is put in the wire in the same format that is displayed.
        And if you comment only the date.setUseTextField(Boolean.TRUE) line then the date in the wire is correctly formatted using the default XMLSchema date format.

        Comment


          #5
          We're not reproducing this issue.

          There has been a recent change in this area that could possibly be responsible - could you try with the next nightly build and let us know if you can still see the problem with the code you attached?
          If so, we'd be interested in seeing exactly what's getting sent across the wire in your example (in both the working and failing case).

          You can grab the raw request from the RPC tab of the developer console: Enable tracking of RPCs, issue the request, then select it in the list to view details. You should be able to copy the content of the request from the section below the list of requests.

          Comment


            #6
            I updated and compiled trunk version (r1517) and I can reproduce the error but it's a little diferent. Now it doesn't works in any case, at least as I expected. But the good point is that it is consistent and the wire format don't depends on the view one.

            The raw request using useTextField is:
            Code:
            date=2010-12-14&_operationType=update&_oldValues=%7B%7D&_componentId=isc_DynamicForm_0&_dataSource=isc_RestDataSource_0&isc_metaDataPrefix=_&isc_dataFormat=json
            And when don't using useTextField is:
            Code:
            date=2010-12-03&_operationType=update&_oldValues=%7B%22date%22%3A%222010-12-02T23%3A00%3A00%22%7D&_componentId=isc_DynamicForm_0&_dataSource=isc_RestDataSource_0&isc_metaDataPrefix=_&isc_dataFormat=json
            According the documentation I expected the date to be in XMLDate format and the only place where I can see the correct value for me is in the oldValues when not using textfield (oldValues=%7B%22date%22%3A%222010-12-02T23%3A00%3A00%22%7D)

            A lot of thanks in advance,
            Last edited by lujop; 3 Dec 2010, 03:54.

            Comment


              #7
              By nightly we mean smartclient.com/builds.

              Comment


                #8
                That builds are accessible by general public? Or I've to wait for the changes to be replicated in the public SVN?

                Comment


                  #9
                  The http://smartclient.com/builds/ directory hosts nightly snapshot builds including SmartClient and SmartGWT LGPL builds for public download, Evaluation builds for public download, and password protected links to Enterprise, Pro and Power builds for customers with the appropriate licenses.

                  Comment

                  Working...
                  X