Announcement

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

    #16
    I followed your instructions by setting the type to "datetime", but the problem still persists. Sample code below:

    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.docs.DateInputFormat;
    import com.smartgwt.client.types.DateDisplayFormat;
    import com.smartgwt.client.types.Overflow;
    import com.smartgwt.client.types.TimeUnit;
    import com.smartgwt.client.widgets.form.fields.events.ChangeEvent;
    import com.smartgwt.client.widgets.form.fields.events.ChangeHandler;
    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>();
    
      private final DateTimeFormat dateFormatter = DateTimeFormat.getFormat(DATE_FORMAT);
      
      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();
    
        changeDateFormat();
        
        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()
            {
               @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.setShortDatetimeDisplayFormatter(new DateDisplayFormatter()
         {
    		public String format(Date date)
            {           
               if(date == null)
               {
            	  System.out.println("date is null");
                  return null;
               }
               else
               {
            	  System.out.println("setShortDatetimeDisplayFormatter = " + date.toString());
                  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)
            {           
               if (dateString == null)
               {
            	   System.out.println("dateString is null");
            	   return null;
               }
               System.out.println("parse = " + dateString);
               Date ret = null;
               try
               {
            	   ret = dateFormatter.parseStrict(dateString);          	   
            	   System.out.println(ret.toString());
               }
               catch (Exception ex)
               {
            	   System.out.println(ex.toString());
               }
               return ret;                      
            }
         });     
         
      }
      
      private RelativeDateItem getStartDateItem()
      {
         if (theStartDateItem == null)
         {     
            theStartDateItem = new RelativeDateItem("start_date");
            theStartDateItem.setTitle("Start");
            theStartDateItem.setShowFutureOptions(false);
            theStartDateItem.setShowPastOptions(true);       
            theStartDateItem.setTimeUnitOptions(getTimeOptions());
            theStartDateItem.setDefaultQuantity(1);        
            theStartDateItem.setPresetOptions(theDatePresets);
            theStartDateItem.setOverflow(Overflow.VISIBLE);           
            theStartDateItem.setType("datetime");
            theStartDateItem.addChangedHandler(new ChangedHandler()
            {
               @Override
               public void onChanged(ChangedEvent event)
               {
                  SC.logWarn("Start ChangedHandler");
               }
            });       
         }
    
         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)
         {        
            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.setType("datetime");
            
            theEndDateItem.addChangedHandler(new ChangedHandler()
            {
               @Override
               public void onChanged(ChangedEvent event)
               {
                  SC.logWarn("End changed handler");
               }
            });        
         }
    
         return theEndDateItem;
      }
      
    }

    Comment


      #17
      Any updates??

      Comment


        #18
        You need a matching dateFormatter on the formItem - for setInputFormat("DMY"), setDateFormatter("toEuropeanShortDatetime") will do it.

        If you still see issues, please retest with a build of March 11 or later, since some other changes in this area have been made today.
        Last edited by Isomorphic; 9 Apr 2013, 23:46.

        Comment


          #19
          Originally posted by Isomorphic View Post
          You need a matching dateFormatter on the formItem - for setInputFormat("DMY"), setDateFormatter("toEuropeanShortDatetime") will do it.

          If you still see issues, please retest with a build of March 11 or later, since some other changes in this area have been made today.
          I re-tested with SmartGWT 03-25-13. Should I get the latest?

          Your suggestion will cause the changed handler to fire, but my custom formatting is lost. It does not format it as 10.Apr.2013 13:50 anymore. It formats it as 10/04/2013 13:50 with the below code:

          Code:
          theStartDateItem.setInputFormat("DMY");
          theStartDateItem.setDateFormatter(DateDisplayFormat.TOEUROPEANSHORTDATETIME);
          theStartDateItem.setDisplayFormat(DateDisplayFormat.TOEUROPOEANSHORTDATETIME);

          Comment


            #20
            Why are you calling setInputFormat() on the FormItem at all? Is that just because your global formatters don't seem to work?

            If so, you should remove that call altogether, since we've just fixed the issue with the global formatters - that will hit nightlies from March 12. You should also get that build for the other fixes we mentioned yesterday.

            Comment


              #21
              Originally posted by Isomorphic View Post
              Why are you calling setInputFormat() on the FormItem at all? Is that just because your global formatters don't seem to work?

              If so, you should remove that call altogether, since we've just fixed the issue with the global formatters - that will hit nightlies from March 12. You should also get that build for the other fixes we mentioned yesterday.
              Because that's what you told me to do. It's not in my latest code snippet.

              At any rate, I upgraded to the latest nightly. The changed handler still does not fire and the calculated date time field does not update. I can see that it is hitting my date formatting code because the "println" statements are executed. However, the changed handler does not fire and the calculated text field does not update.

              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.docs.DateInputFormat;
              import com.smartgwt.client.types.DateDisplayFormat;
              import com.smartgwt.client.types.Overflow;
              import com.smartgwt.client.types.TimeUnit;
              import com.smartgwt.client.widgets.form.fields.events.ChangeEvent;
              import com.smartgwt.client.widgets.form.fields.events.ChangeHandler;
              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>();
              
                private final DateTimeFormat dateFormatter = DateTimeFormat.getFormat(DATE_FORMAT);
                
                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();
              
                  changeDateFormat();
                  
                  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()
                      {
                         @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.setShortDatetimeDisplayFormatter(new DateDisplayFormatter()
                   {
              		public String format(Date date)
                      {           
                         if(date == null)
                         {
                      	  System.out.println("date is null");
                            return null;
                         }
                         else
                         {
                      	  System.out.println("setShortDatetimeDisplayFormatter = " + date.toString());
                            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)
                      {           
                         if (dateString == null)
                         {
                      	   System.out.println("dateString is null");
                      	   return null;
                         }
                         System.out.println("parse = " + dateString);
                         Date ret = null;
                         try
                         {
                      	   ret = dateFormatter.parseStrict(dateString);          	   
                      	   System.out.println(ret.toString());
                         }
                         catch (Exception ex)
                         {
                      	   System.out.println(ex.toString());
                         }
                         return ret;                      
                      }
                   });     
                   
                }
                
                private RelativeDateItem getStartDateItem()
                {
                   if (theStartDateItem == null)
                   {     
                      theStartDateItem = new RelativeDateItem("start_date");
                      theStartDateItem.setTitle("Start");
                      theStartDateItem.setShowFutureOptions(false);
                      theStartDateItem.setShowPastOptions(true);       
                      theStartDateItem.setTimeUnitOptions(getTimeOptions());
                      theStartDateItem.setDefaultQuantity(1);        
                      theStartDateItem.setPresetOptions(theDatePresets);
                      theStartDateItem.setOverflow(Overflow.VISIBLE);           
                      
                      theStartDateItem.addChangedHandler(new ChangedHandler()
                      {
                         @Override
                         public void onChanged(ChangedEvent event)
                         {
                            SC.logWarn("Start ChangedHandler");
                         }
                      });       
                   }
              
                   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)
                   {        
                      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;
                }
                
              }

              Comment


                #22
                We told you to add a matching formatter, because you had already called setInputFormat() on the item. Unless you want the control to have a different inputFormat than the global one, that isn't necessary, but if you do it, you need a matching formatter.

                As we also said, the fixes you need will appear in nightlies from builds dated March 12, and that build isn't even on the site yet. Please retest with the next one.

                Comment


                  #23
                  Originally posted by Isomorphic View Post
                  We told you to add a matching formatter, because you had already called setInputFormat() on the item. Unless you want the control to have a different inputFormat than the global one, that isn't necessary, but if you do it, you need a matching formatter.

                  As we also said, the fixes you need will appear in nightlies from builds dated March 12, and that build isn't even on the site yet. Please retest with the next one.
                  Do you mean April 12th?

                  I had added setInputFormat() because you told me to in another thread. And then you told me later on, to just post the latest code snippet after testing in Mid-March. So that's what I did. I assumed you were working with the latest snippet I had posted as you directed.

                  Comment


                    #24
                    Ah yes, April, of course :)

                    Comment


                      #25
                      Originally posted by Isomorphic View Post
                      Ah yes, April, of course :)
                      Woo hoo! It works! :)

                      I don't know if it matters, but I added setType("datetime");

                      I am not using setInputFormat or any of the other adjoining formatters, just the global formatters.

                      Comment


                        #26
                        It's not clear if you're asking a question here?

                        On the setType() call - yes, and this was covered earlier in this or the other thread - if your RelativeDateItem is not bound to a DataSource field that specifies type, you need to specify type on the item, since there are separate global formatters for dates and datetimes

                        Comment

                        Working...
                        X