Announcement

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

    RelativeDateItem Stops Firing Changes

    SmartGWT 3.1p 03-14-2013 nightly
    GWT 2.5
    ---

    When .setInputFormat("DMY") is set on my RelativeDateItem with a date format of dd.MMM.yyyy HH:mm, the Changed Handler only fires once upon selecting a date from the calendar picker. The calculated date field goes blank and typing into the text entry field does not fire the Changed Handler. When I remove setInputFormat("DMY"), the Changed Handler fires for each subsequent selection of a date from the calendar picker. It does not fire for minor changes to the time, such as changing the 00:00 to 00:01. How can I get the Changed Handler to fire on a keypress? Should I attach a KeyPressHandler too? This used to work great.

    Another thing I noticed is before I started using setInputFormat("DMY"), I used to be able to call (Date) theStartDateItem.getValue() because getValue would return a LogicalDate; however, with setInputFormat("DMY"), getValue() returns a String instead.

    Other than using instanceof or isAssignableFrom, can I guarantee the type that is returned from getValue()?

    Code:
    package com.corp.smartgwt.client;
    
    
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.i18n.client.DateTimeFormat;
    import com.smartgwt.client.widgets.Canvas;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.layout.HLayout;
    import com.smartgwt.client.util.DateUtil;
    import com.smartgwt.client.widgets.form.fields.RadioGroupItem;
    import com.smartgwt.client.widgets.form.fields.RelativeDateItem;
    import com.smartgwt.client.util.DateDisplayFormatter;
    import com.smartgwt.client.util.DateParser;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.data.RelativeDate;
    import com.smartgwt.client.types.Overflow;
    import com.smartgwt.client.types.TimeUnit;
    import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
    import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
    import com.smartgwt.client.widgets.form.fields.events.ShowValueEvent;
    import com.smartgwt.client.widgets.form.fields.events.ShowValueHandler;
    import com.smartgwt.client.widgets.form.validator.DateRangeValidator;
    
    import java.util.Date;
    import java.util.LinkedHashMap;
    
    public class SmartGwt implements EntryPoint {
    
      private RelativeDateItem theStartDateItem;
      private RelativeDateItem theEndDateItem;
      private static String DATE_FORMAT = "dd.MMM.yyyy HH:mm";
    	
      private static String RADIOGROUP_NAME = "radiogroup1";
    	   
      private RadioGroupItem theFilterRadioGroup;
    	   
      private static final String RB1_LABEL_TEXT = "Disable";
    
      private static final String RB2_LABEL_TEXT = "Set Value Now and Enable";
    
      private static final String RB3_LABEL_TEXT = "Just Enable";
    	
      private final static LinkedHashMap<String, String> theDatePresets = new LinkedHashMap<String, String>();
    
      static
      {
         theDatePresets.put("$now",       "Now");
         theDatePresets.put("$today",     "Today");
         theDatePresets.put("$yesterday", "Yesterday");
         theDatePresets.put("$tomorrow",  "Tomorrow");
         theDatePresets.put("-1w",        "Current day of last week");
         theDatePresets.put("+1w",        "Current day of next week");
         theDatePresets.put("+1m",        "Current day of next month");
         theDatePresets.put("-1m",        "Current day of last month");
      }
    	
      @Override
      public void onModuleLoad() {
        HLayout layout = new HLayout();
        DynamicForm form = new DynamicForm();
        
    
        form.setFields(getFilterRadioGroup(), getStartDateItem(), getEndDateItem());
        layout.addMember(form);
        layout.draw();
        
    
      }
      
      /**
       * This method returns a RadioGroupItem consisting of None,
       * Image Date, and Load Date. It uses lazy initialization.
       * @return RadioGroupItem
       */
      private RadioGroupItem getFilterRadioGroup()
      {
         if (theFilterRadioGroup == null)
         {
            theFilterRadioGroup = new RadioGroupItem(RADIOGROUP_NAME);
            theFilterRadioGroup.setValueMap(RB1_LABEL_TEXT,
                                            RB2_LABEL_TEXT,
                                            RB3_LABEL_TEXT);
            theFilterRadioGroup.setShowTitle(false);        
            theFilterRadioGroup.setDefaultValue(RB1_LABEL_TEXT);
            theFilterRadioGroup.setGlobalTabIndex(21);
    
            getStartDateItem().setDisabled(true);
            getEndDateItem().setDisabled(true);
            
            theFilterRadioGroup.addChangedHandler(new ChangedHandler()
            {
               /*
                * This method should fire anytime a user changes the radio button selection.
                */
               @Override
               public void onChanged(ChangedEvent event)
               {
                  if (theFilterRadioGroup.getValueAsString().equals(RB1_LABEL_TEXT))
                  {
                	  getStartDateItem().setDisabled(true);
                	  getEndDateItem().setDisabled(true);
                  }
                  else if (theFilterRadioGroup.getValueAsString().equals(RB2_LABEL_TEXT))
                  {
                      
                      getStartDateItem().enable();                  
                      getEndDateItem().enable();
                      getStartDateItem().setValue("$now");
                  }
                  else
                  {
                	  getStartDateItem().enable();                  
                      getEndDateItem().enable();                  
                  }
               }
            });
         }
    
         return theFilterRadioGroup;
      }
      
      private void changeDateFormat()
      {      
    	 DateUtil.setDefaultDisplayTimezone("-04:00");
    	 
         DateUtil.setShortDatetimeDisplayFormatter(new DateDisplayFormatter()
         {
            public String format(Date date)
            {
               if(date == null)
               {
                  return null;
               }
               else
               {
                  final DateTimeFormat dateFormatter = DateTimeFormat.getFormat(DATE_FORMAT);
                  return dateFormatter.format(date);
               }
            }
         });
    
         // It is a requirement that we implement a custom date parser or the onChanged event
         // will not fire.
         
         DateUtil.setDateParser(new DateParser()
         {
            public Date parse(String dateString)
            {           
               final DateTimeFormat format = DateTimeFormat.getFormat(DATE_FORMAT);
               return format.parse(dateString);                      
            }
         });
      }
      
      private RelativeDateItem getStartDateItem()
      {
         if (theStartDateItem == null)
         {
            changeDateFormat();
    
            theStartDateItem = new RelativeDateItem("start_date");
            theStartDateItem.setTitle("Start");
            theStartDateItem.setShowFutureOptions(false);
            theStartDateItem.setShowPastOptions(true);       
            
            theStartDateItem.setTimeUnitOptions(getTimeOptions());
            theStartDateItem.setDefaultQuantity(1); 
            theStartDateItem.setValue(new RelativeDate("-1d"));
            
            theStartDateItem.setPresetOptions(theDatePresets);
            theStartDateItem.setInputFormat("DMY");
            theStartDateItem.setOverflow(Overflow.VISIBLE);    
                            
            theStartDateItem.addChangedHandler(new ChangedHandler()
            {
               @Override
               public void onChanged(ChangedEvent event)
               {
                  SC.logWarn("Start ChangedHandler");
                  // This will cause an exception Cannot convert String to Date
            	  //Date startDate = (Date)theStartDateItem.getValue();
                  String startDate = (String) theStartDateItem.getValue();
                  
            	  SC.logWarn("startDate = " + startDate);
               }
            });
         }
    
         return theStartDateItem;
      }
    
      /**
       * This will return an array of SmartGWT TimeUnit options that we want to add to our drop-down
       * for the Start and End date RelativeDateItem's
       *
       * @return array of TimeUnit's
       */
      private TimeUnit[] getTimeOptions()
      {
          TimeUnit[] units = new TimeUnit[5];
    
          units[0] = TimeUnit.HOUR;
          units[1] = TimeUnit.DAY;
          units[2] = TimeUnit.WEEK;
          units[3] = TimeUnit.MONTH;
          units[4] = TimeUnit.YEAR;
    
          return units;
      }
    
      /**
       * This will initialize and construct the end RelativeDateItem
       * @return Ending RelativeDateItem
       */
      private RelativeDateItem getEndDateItem()
      {
         if (theEndDateItem == null)
         {
            changeDateFormat();
            
            theEndDateItem = new RelativeDateItem("end_date");
            theEndDateItem.setTitle("End:");         
            
            theEndDateItem.setOverflow(Overflow.VISIBLE);
            theEndDateItem.setShowFutureOptions(false);
            theEndDateItem.setShowPastOptions(true);
            theEndDateItem.setTimeUnitOptions(getTimeOptions());
            theEndDateItem.setDefaultQuantity(1);
            
            theEndDateItem.setPresetOptions(theDatePresets);
    
            theEndDateItem.addChangedHandler(new ChangedHandler()
            {
               @Override
               public void onChanged(ChangedEvent event)
               {
                  SC.logWarn("End changed handler");
               }
            });        
         }
    
         return theEndDateItem;
      }
      
    }
    Last edited by bwilkins30; 15 Mar 2013, 04:33.

    #2
    The issue is in the date formatting code, I just don't know why this would be happening at all. SmartGWT 3.1p from Sept-2012 did not have this problem. When I comment out the date formatting code, the change handler properly fires. However, it now returns a String and not a Date as I would expect. I am guessing that before the custom parser would return a Date object?

    Comment


      #3
      Please switch on info level logging for Date and let us know if you're getting logs along the lines of "Unable to determine input format associated with display format function ...."

      Comment


        #4
        Originally posted by Isomorphic View Post
        Please switch on info level logging for Date and let us know if you're getting logs along the lines of "Unable to determine input format associated with display format function ...."
        I added the category Date and set it to Info. I saw no messages in the console. So I set the level to Info globally and these are the message I receive

        Code:
        09:59:02.076:KDN8:INFO:EventHandler:keyDown event with Canvas target: [ComboBoxItem ID:isc_ComboBoxItem_0 name:valueField], native target: [INPUTElement]{name:valueField}
        09:59:02.083:INP0:INFO:RPCManager:sendQueue called with no current queue, ignoring
        09:59:02.086:INP0:INFO:sizing:isc_PickListMenu_0_body:Specified size: 146x102, drawn scroll size: 144x100, border: 2x2, margin: 0x0, reason: undefined
        09:59:02.086:INP0:INFO:scrolling:isc_PickListMenu_0_body:Drawn size: 144 by 100, specified: 146 by 102, scrollbar state: 
        09:59:02.087:INP0:INFO:sizing:isc_PickListMenu_0_body:Specified size: 146x102, drawn scroll size: 144x100, border: 2x2, margin: 0x0, reason: undefined
        09:59:02.087:INP0:INFO:scrolling:isc_PickListMenu_0_body:Drawn size: 144 by 100, specified: 146 by 102, scrollbar state: 
        09:59:02.087:INP0:INFO:sizing:isc_PickListMenu_0_body:Specified size: 146x102, drawn scroll size: 144x100, border: 2x2, margin: 0x0, reason: undefined
        09:59:02.087:INP0:INFO:scrolling:isc_PickListMenu_0_body:Drawn size: 144 by 100, specified: 146 by 102, scrollbar state: 
        09:59:02.306:TMR2:INFO:redraws:isc_PickListMenu_0_body:Scheduling redraw (setData)
        09:59:02.308:TMR3:INFO:recordComponents:isc_PickListMenu_0:updateRecordComponents - new recordComponents:{}, old record components (will be cleaned up if value is 'true'):{}
        09:59:02.309:TMR3:INFO:drawing:isc_PickListMenu_0_body:$ra(): redrawing
        09:59:02.311:TMR3:INFO:sizing:isc_PickListMenu_0_body:Specified size: 146x102, drawn scroll size: 144x100, border: 2x2, margin: 0x0, reason: redraw
        09:59:02.311:TMR3:INFO:scrolling:isc_PickListMenu_0_body:Drawn size: 144 by 100, specified: 146 by 102, scrollbar state: 
        09:59:16.652:KDN4:INFO:EventHandler:keyDown event with Canvas target: [ComboBoxItem ID:isc_ComboBoxItem_0 name:valueField], native target: [INPUTElement]{name:valueField}
        09:59:16.656:INP6:INFO:RPCManager:sendQueue called with no current queue, ignoring
        09:59:16.659:INP6:INFO:sizing:isc_PickListMenu_0_body:Specified size: 146x102, drawn scroll size: 144x100, border: 2x2, margin: 0x0, reason: undefined
        09:59:16.659:INP6:INFO:scrolling:isc_PickListMenu_0_body:Drawn size: 144 by 100, specified: 146 by 102, scrollbar state: 
        09:59:16.660:INP6:INFO:sizing:isc_PickListMenu_0_body:Specified size: 146x102, drawn scroll size: 144x100, border: 2x2, margin: 0x0, reason: undefined
        09:59:16.660:INP6:INFO:scrolling:isc_PickListMenu_0_body:Drawn size: 144 by 100, specified: 146 by 102, scrollbar state: 
        09:59:16.661:INP6:INFO:sizing:isc_PickListMenu_0_body:Specified size: 146x102, drawn scroll size: 144x100, border: 2x2, margin: 0x0, reason: undefined
        09:59:16.661:INP6:INFO:scrolling:isc_PickListMenu_0_body:Drawn size: 144 by 100, specified: 146 by 102, scrollbar state: 
        09:59:16.884:TMR8:INFO:redraws:isc_PickListMenu_0_body:Scheduling redraw (setData)
        09:59:16.887:TMR9:INFO:recordComponents:isc_PickListMenu_0:updateRecordComponents - new recordComponents:{}, old record components (will be cleaned up if value is 'true'):{}
        09:59:16.889:TMR9:INFO:drawing:isc_PickListMenu_0_body:$ra(): redrawing
        09:59:16.893:TMR9:INFO:sizing:isc_PickListMenu_0_body:Specified size: 146x102, drawn scroll size: 144x100, border: 2x2, margin: 0x0, reason: redraw
        09:59:16.893:TMR9:INFO:scrolling:isc_PickListMenu_0_body:Drawn size: 144 by 100, specified: 146 by 102, scrollbar state:

        Comment


          #5
          I put some additional logging into the code and this is the trace that occurs when the code enters the format portion after parsing what the user typed in:

          Code:
          com.smartgwt.client.core.JsObject$SGWT_WARN: 14:43:52.391:WARN:Log:in format
              at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
              at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
              at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
              at java.lang.reflect.Constructor.newInstance(Unknown Source)
              at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:105)
              at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
              at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
              at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
              at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
              at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
              at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
              at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:299)
              at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
              at com.smartgwt.client.util.SC.logWarn(SC.java)
              at com.corp.smartgwt.client.SmartGwt$2.format(SmartGwt.java:131)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
              at java.lang.reflect.Method.invoke(Unknown Source)
              at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
              at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
              at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
              at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
              at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
              at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
              at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
              at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
              at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
              at com.smartgwt.client.widgets.form.DynamicForm.create(DynamicForm.java)
              at com.smartgwt.client.widgets.BaseWidget.getOrCreateJsObj(BaseWidget.java:391)
              at com.smartgwt.client.widgets.layout.Layout.addMember(Layout.java:1229)
              at com.corp.smartgwt.client.SmartGwt.onModuleLoad(SmartGwt.java:65)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
              at java.lang.reflect.Method.invoke(Unknown Source)
              at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:406)
              at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
              at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:526)
              at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
              at java.lang.Thread.run(Unknown Source)
          It doesn't have a problem parsing, it stops when it returns to the format().

          Comment


            #6
            More information... Changing the Day, Month, or Year works great. Changing the time is where the problem lies. It does not fire the change handler if the user changes the time.

            Comment


              #7
              I found that setInputFormat setting had no effect on my issue. For some reason editing the time causes the change handler not to fire and none of the formatting functions in changeDateFormat are called either. Very odd.

              Comment


                #8
                This FF17.0.2ESR, Windows7, en-us locale by the way

                Comment


                  #9
                  Any idea why all of a sudden this stopped working?

                  Comment


                    #10
                    I have worked on this and can't do much more without Isomorphic looking into it. Basically, the Changed Handler used to fire when you changed the time in the RelativeDateItem text entry field. It no longer does that. It will fire the Changed Handler if you change the date. I tried setting the DateDisplayFormat to USSHORTDATETIME, but that had no effect. Unfortunately for me, I can't use the latest SmartGWT until this problem is addressed, which includes the "Now" fix. I rely on having the user be able to change the time in the RelativeDateItem.

                    Comment


                      #11
                      I compared the source code from SmartGWT 3.0p 09-20-2012 to SmartGWT 3.1p 03-18-2013. I am not sure if this matters, but it looks like in DateUtil, there was a change to setShortDatetimeDisplayFormat

                      from

                      Code:
                          public static native void setShortDateDisplayFormatter(DateDisplayFormatter formatter) /*-{
                              $wnd.Date.setShortDisplayFormat(function() {
                                      var date = this;
                                      var dateJ = date == null || date === undefined ? null : @com.smartgwt.client.util.JSOHelper::toDate(D)(date.getTime());
                                      return formatter.@com.smartgwt.client.util.DateDisplayFormatter::format(Ljava/util/Date;)(dateJ);
                                  }
                              );
                          }-*/;
                      to

                      Code:
                          public static native void setShortDatetimeDisplayFormatter(DateDisplayFormatter formatter) /*-{
                              var formatterJS = @com.smartgwt.client.util.DateUtil::convertDateDisplayFormatterToJS(Lcom/smartgwt/client/util/DateDisplayFormatter;)(formatter);
                              $wnd.Date.setShortDatetimeDisplayFormat(formatterJS);
                          }-*/;

                      Comment


                        #12
                        In SmartGWT 4.0d 03-18-2013, you can select the time from the calendar picker. That capability is not in 3.1p. I am not sure if maybe 3.1p is being prepared for that capability, but if we at least had that, it would be great.

                        Comment


                          #13
                          In 4.0, the DateChooser has essentially been completely re-written, based on a ListGrid and taking advantage of the useTextField:false mode of TimeItem, which is also new to 4.0. Therefore, it is most unlikely that this feature will be ported to 3.1p.

                          However.

                          An engineer is looking into these issues in 3.1p and will update this thread with more information and solutions once they're available.
                          Last edited by Isomorphic; 18 Mar 2013, 21:34.

                          Comment


                            #14
                            You haven't told the RelativeDateItem whether it's dealing with a date or a datetime. Ordinarily, this would come from the type of the DataSource field, but your test code is unbound.

                            Try calling item.setType("datetime"), if that's how you want the value parsing. That should improve things for you.

                            If you still see issues, please repost your test code as it now appears.

                            Comment


                              #15
                              Originally posted by Isomorphic View Post
                              You haven't told the RelativeDateItem whether it's dealing with a date or a datetime. Ordinarily, this would come from the type of the DataSource field, but your test code is unbound.

                              Try calling item.setType("datetime"), if that's how you want the value parsing. That should improve things for you.

                              If you still see issues, please repost your test code as it now appears.
                              Ok, will try this. Thanks for responding and tracking this down.

                              Comment

                              Working...
                              X