Announcement

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

    Event Handler Problem with RelativeDateItem in Showcase 3.1p

    SmartClient Version: v8.3p_2013-01-22/LGPL Development Only (built 2013-01-22)

    FF 17.0.2 ESR

    GWT 2.4

    Windows 7

    Executed test in FF 17.0.2 ESR browser itself
    ---

    I am receiving this warning whenever I try to interact with the RelativeDateItem. On my form, I have two RelativeDateItems and when I interact with the first one, I see the following warning. However, after interacting with the second, the warning goes away and the event handlers work properly.

    Looking at the Showcase Example "Various Form Controls", I observed the same warning in the Developers Console. There may be an issue with RelativeDateItem that needs to be addressed:

    Code:
    14:11:03.246:IFCS1:WARN:StaticTextItem:isc_StaticTextItem_4[iconPlaceholder]:Attempting to apply event handlers to this item. Unable to get a pointer to this item's focus element
    This is what I see on my system with two relative date items

    Code:
    14:15:07.147:TMR6:WARN:StaticTextItem:isc_StaticTextItem_0:Attempting to apply event handlers to this item. Unable to get a pointer to this item's focus element
    14:15:07.158:TMR6:WARN:StaticTextItem:isc_StaticTextItem_1:Attempting to apply event handlers to this item. Unable to get a pointer to this item's focus element
    14:15:07.887:RDQ1:WARN:StaticTextItem:isc_StaticTextItem_0:Attempting to apply event handlers to this item. Unable to get a pointer to this item's focus element
    14:15:07.899:RDQ1:WARN:StaticTextItem:isc_StaticTextItem_1:Attempting to apply event handlers to this item. Unable to get a pointer to this item's focus element
    Last edited by bwilkins30; 24 Jan 2013, 12:47.

    #2
    Here is a snippet which exhibits the problem. The following exception is thrown initially upon selecting the first RelativeDateItem. The exception is only thrown until you select the second RelativeDateItem and then the exception no longer occurs.

    ---EXCEPTION----

    Uncaught exception escaped : com.google.gwt.event.shared.UmbrellaException
    Exception caught: java.lang.String cannot be cast to java.util.Date
    See the Development console log for details.
    Register a GWT.setUncaughtExceptionHandler(..) for custom uncaught exception handling.

    Code:
    package com.corp.smartgwt.client;
    
    import java.util.LinkedHashMap;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.i18n.client.DateTimeFormat;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.fields.SelectItem;
    import com.smartgwt.client.widgets.layout.HLayout;
    import com.smartgwt.client.util.DateUtil;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.form.fields.RelativeDateItem;
    import com.smartgwt.client.util.DateDisplayFormatter;
    import com.smartgwt.client.util.DateParser;
    import com.smartgwt.client.data.DateRange;
    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.data.DateRange;
    import java.util.Date;
    
    public class SmartGwt implements EntryPoint {
    
    	private RelativeDateItem theStartDateItem;
    	private RelativeDateItem theEndDateItem;
    	private static String DATE_FORMAT = "dd.MMM.yyyy kk:mm";
    	
      @Override
      public void onModuleLoad() {
        HLayout layout = new HLayout();
        DynamicForm form = new DynamicForm();
        form.setFields(getStartDateItem(), getEndDateItem());
        layout.addMember(form);
        layout.draw();
      }
      
      private void changeDateFormat()
      {      
         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);
            
            // By setting this to essentially a blank LinkedHashMap, it will clear out the preset
            // options we do not want.
            // theStartDateItem.setPresetOptions(new LinkedHashMap());
            
            theStartDateItem.setTimeUnitOptions(getTimeOptions());
            theStartDateItem.setDefaultQuantity(1);
            
            // This DateRangeValidator will prevent us from setting the startDate in the future
            // past Today
    //        DateRangeValidator startValidator = new DateRangeValidator();
    //        startValidator.setMax(new Date());
    //        
    //        theStartDateItem.setValidators(startValidator);
    //        theStartDateItem.setValidateOnChange(true);
    
            // sets it to $today, which is a built-in option
            theStartDateItem.setValue(RelativeDate.TODAY.toString());
            theStartDateItem.setOverflow(Overflow.VISIBLE);        
            
            theStartDateItem.addChangedHandler(new ChangedHandler()
            {
               @Override
               public void onChanged(ChangedEvent event)
               {
                  SC.logWarn("Start Date Changed!");
                  // Test if this is a relative date selection so we can save it that way
                  RelativeDate relDate = theStartDateItem.getRelativeDate();
                  
                  Date startDate = (Date)theStartDateItem.getValue();
                  Date endDate = (Date)getEndDateItem().getValue();
    
                  SC.logWarn(startDate.toString());
                  
                  // Per the JavaDoc, compareTo returns less than 0 if the date is before the compared
                  // date. So in this case, if the endDate is before the startDate, then we show
                  // the error. No changes will be made to the model until the error is cleared.
                  if (endDate.compareTo(startDate) < 0)
                  {
                     getEndDateItem().getForm()
                                   .setFieldErrors("end_date", "invalid date", true);
                  }               
                  else
                  {                  
                     getEndDateItem().getForm()
                                     .clearFieldErrors("end_date", true);
                   
                     if (relDate != null)
                     {
                        SC.logWarn("Start Relative Date: " + relDate.getValue());
                     }
                  }
               }
            });
    
            // 
         }
    
         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:");         
    
            // By setting this to essentially a blank LinkedHashMap, it will clear out the preset
            // options we do not want.
            // theEndDateItem.setPresetOptions(new LinkedHashMap());
            
            theEndDateItem.setOverflow(Overflow.VISIBLE);
            theEndDateItem.setShowFutureOptions(false);
            theEndDateItem.setShowPastOptions(true);
            theEndDateItem.setTimeUnitOptions(getTimeOptions());
            theEndDateItem.setDefaultQuantity(1);
            theEndDateItem.setValue(RelativeDate.TODAY.toString());
    
            theEndDateItem.addChangedHandler(new ChangedHandler()
            {
               @Override
               public void onChanged(ChangedEvent event)
               {
                  SC.logWarn("End date item changed!");
                  // Test if this is a relative date selection so we can save it that way
                  RelativeDate relDate = theEndDateItem.getRelativeDate();
                  
                  Date startDate = (Date)getStartDateItem().getValue();
                  Date endDate = (Date)theEndDateItem.getValue();
    
                  // Per the JavaDoc, compareTo returns less than 0 if the date is before the compared
                  // date. So in this case, if the endDate is before the startDate, then we show
                  // the error.
                  if (endDate.compareTo(startDate) < 0)
                  {
                     theEndDateItem.getForm()
                                   .setFieldErrors("end_date", "invalid date", true);
                  }
                  else
                  {
                     // Clear any errors on the field and save the changes to the model
                     theEndDateItem.getForm()
                                   .clearFieldErrors("end_date", true);
    
                     if (relDate != null)
                     {
                        SC.logWarn("End Relative Date: " + relDate.getValue());
                     }                 
                  }
               }
            });        
         }
    
         return theEndDateItem;
      }
    }
    From Dev Console:

    Code:
    com.smartgwt.client.core.JsObject$SGWT_WARN: 15:49:20.190:WARN:StaticTextItem:isc_StaticTextItem_0[iconPlaceholder]:Attempting to apply event handlers to this item. Unable to get a pointer to this item's focus element
        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.invokeNativeObject(ModuleSpace.java:279)
        at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
        at com.smartgwt.client.widgets.BaseWidget.getInnerHTML(BaseWidget.java)
        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.invokeNativeVoid(ModuleSpace.java:299)
        at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
        at com.smartgwt.client.widgets.BaseWidget.draw(BaseWidget.java)
        at com.corp.smartgwt.client.SmartGwt.onModuleLoad(SmartGwt.java:36)
        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)
    Last edited by bwilkins30; 24 Jan 2013, 12:51.

    Comment


      #3
      BTW, commenting out changeDateFormat() does not fix the problem nor does keeping changeDateFormat() and adding a try/catch.

      Comment


        #4
        Ok, here is the source of the problem:

        For some reason when you call .setValue initially, it causes this problem. When I took out the .setValue on the RelativeDateItem's, the exception no longer occurs. Look at the code to see.

        Comment


          #5
          Any idea why calling setValue would cause this to happen?

          Comment


            #6
            We've assigned one of our developers to take a look. We'll update the thread when we have more information

            Regards
            Isomorphic Software

            Comment


              #7
              Hello bwilkins30,

              The problem here is that you are passing a String as the value for setValue(). If you create an instance of RelativeDate instead, that should work.

              Comment


                #8
                That's odd because .getValue() returns a String and setValue does not accept an instance of RelativeDate. If you call .getValue() when the user selects say Tomorrow, .getValue() on the RelativeDateItem will return $tomorrow. But I will try it nonetheless. I suppose it will work because RelativeDate derives from Object and setValue accepts an Object.
                Last edited by bwilkins30; 30 Jan 2013, 12:11.

                Comment


                  #9
                  Actually, setValue("$today") should have worked, but your explicit call to toString() is probably tripping a core GWT bug covered in the FAQ (String serialized as though it was an array..).

                  You can upgrade to GWT 2.5 to get rid of this (for this case and others).

                  Comment


                    #10
                    Thanks, that makes sense. I wasn't aware it was in the FAQ and now I am much smarter about GWT than before. I appreciate you responding and teaching me something new.

                    Comment

                    Working...
                    X