Announcement

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

    SpinnerItem issue with EditorValueFormatter

    Using smartgwt 2.4, the editor FormItemValueFormatter seems to only fire on load and not when the value is changed (through the spinner or typing). The FormItemValueParser fires all the time. Has anyone else come across this? Here's an example:

    Code:
    package mytest.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.core.client.GWT;
    import com.smartgwt.client.data.Record;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.fields.SpinnerItem;
    import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
    import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
    
    /**
     * Entry point classes define <code>onModuleLoad()</code>.
     */
    public class Testsgwt implements EntryPoint {
    
        /**
         * This is the entry point method.
         */
        public void onModuleLoad() {
    
            final DynamicForm styleForm = new DynamicForm();
            SpinnerItem spinner = new SpinnerItem();
            spinner.setName("field");
            spinner.setMin(0.0d);
            spinner.setStep(1.0d);
    	spinner.setEditorValueFormatter(new FormItemValueFormatter (){
    		@Override
    		public String formatValue(Object value, Record record, DynamicForm form, FormItem item) {
    			if (value == null) {GWT.log("null formatting");
    				return null; 
    			}
    			try {GWT.log("formatting");
    				Double val = new Double(value.toString());
    				Double valplusone = val + 1;
    				return valplusone.toString();
    			} catch (Exception e) {GWT.log(e.getMessage());
    				return null;
    			}
    		}
    	});
    
            styleForm.setFields(spinner);
            styleForm.draw();
    
        }
    }

    #2
    Anyone solved this issue?

    Comment


      #3
      I'm using SmartGWT 2.4 and seeing similar SpinnerItem bugs where FormItem ChangedEvents are never fired for SpinnerItems, and DynamicForm ItemChangedEvents are only fired when the value is changed by clicking on the spinner's up/down icons.

      Here's a minimal sample that demonstrates the bugs:

      Code:
      package test.client;
      
      import com.google.gwt.core.client.EntryPoint;
      import com.google.gwt.core.client.GWT;
      import com.smartgwt.client.util.SC;
      import com.smartgwt.client.widgets.form.DynamicForm;
      import com.smartgwt.client.widgets.form.events.ItemChangedEvent;
      import com.smartgwt.client.widgets.form.events.ItemChangedHandler;
      import com.smartgwt.client.widgets.form.fields.SpinnerItem;
      import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
      import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
      
      /**
       * Entry point for test SmartGWT GWT module.
       */
      public class Application implements EntryPoint {
          /**
           * This is called when the browser loads Application.html.
           */
          public void onModuleLoad() {
              GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() {
                  public void onUncaughtException(Throwable t) {
                      System.err.println("--- UNCAUGHT EXCEPTION ---");
                      t.printStackTrace();
                  }
              });
      
              SpinnerItem spinner = new SpinnerItem();
              spinner.setName("field");
              // BUG #1: FormItem ChangedEvents are *not* fired when a spinner's value is changed by clicking on its up/down
              //         icons, *nor* when its value is changed by manually changing the text in its text input field.
              spinner.addChangedHandler(new ChangedHandler() {
                  @Override
                  public void onChanged(ChangedEvent changedEvent) {
                      SC.say("Spinner value changed! (ChangedEvent)");
                  }
              });
      
              final DynamicForm form = new DynamicForm();
              form.setMargin(10);
              form.setFields(spinner);
              // BUG #2: DynamicForm ItemChangedEvents are fired when a spinner's value is changed by clicking on the up/down
              //         icons, but they are *not* fired when its value is changed by manually changing the text in its text
              //         input field.
              form.addItemChangedHandler(new ItemChangedHandler() {
                  @Override
                  public void onItemChanged(ItemChangedEvent itemChangedEvent) {
                      SC.say("Spinner value changed! (ItemChangedEvent)");
                  }
              });
              form.draw();
          }
      }

      Comment


        #4
        Before even looking at the test case - why are you still on 2.4? 2.5 has been out for some time.

        Comment


          #5
          I'm an employee of Red Hat and a developer on the RHQ project. RHQ is an open-source management and monitoring platform run by Red Hat. The GUI of RHQ 4.0 and later is SmartGWT-based. Earlier versions of the GUI were based on JSF and RichFaces.

          We do plan on eventually upgrading to SmartGWT 2.5 (see https://bugzilla.redhat.com/show_bug.cgi?id=694221). However, we can't just immediately upgrade any time a new version comes out for a couple reasons:

          1) RHQ has a good number of users, some using RHQ in production environments, so we like to do a considerable amount of testing for regressions caused by a major component upgrade before moving ahead with that upgrade.
          2) The JBoss Operations Network (JON) product is a fully-supported Red Hat product based on RHQ. We need to do an even higher level of QA for major changes that go into JON (which includes most things that go into RHQ). This involves testing across all our supported hardware platforms, operating systems, locales, Java versions, and browsers, so major component upgrades need to be deemed to provide sufficient value-add considering the testing effort involved, and they also need to be timed so that they're well in advance of the next major JON release.

          Comment


            #6
            Very typical concerns, but they mean that:

            1. you should upgrade to the latest at the beginning of each development cycle, so that you can get potentially get patches. Like any software company, we don't usually release functional patches for old versions (only security patches). Not sure where you are right now in the cycle, but presumably this issue is based on new code.

            2. in case you need patches to older versions, you should get an Enterprise Support plan, which includes unlimited patches.

            On your particular test case, are you trying this in a completely clean environment (no other GWT modules or third-party technology)?

            Comment


              #7
              Also, having confirmed that your test case is from a clean environment, please verify that this can be reproduced without the use of SC.say() - this shows a modal dialog and could interfere with event handling. Just log the values instead.

              Finally, can you indicate the remaining basics: browser(s) tested, version of GWT, etc.

              Comment


                #8
                Yes, I agree - the time to upgrade is right near the start of a new release lifecycle. Unfortunately, we're way past that window for our upcoming JON 3.0 release, so it will probably be 2-3 months before we can move up to 2.4. I understand that this can't be fixed in 2.4, since that's not the current release, but I still wanted to post it for the benefit of any other users hitting the same issues and to make you aware of it so you can make sure it's not still in an issue in the latest 2.6 code.

                Yes, I have a very minimal WAR running in a minimal Jetty server. It doesn't include any other 3rd-party jars. I'm using Java 6.0 u29, Firefox 3.6.23, and GWT 2.0.4.

                Thanks for the tip on removing the SC.say() calls. After replacing them with System.out.println() calls, I am seeing differences. Note, I also added code to test ChangeEvents and ItemChangeEvents, in addition to ChangedEvents and ItemChangedEvents. Finally, I added an IntegerItem to the form as a basis for comparison with the SpinnerItem.

                For the SpinnerItem, if I change the value using the up/down arrow buttons, all four types of change events immediately fire, so that looks good. However, if I change the value by manually editing the text input, none of the events fire. Only once I switch focus from the text input to something else, does a *single* set of the four types of change events fires. So, for example, if I change the value from "1" to "123", and then change focus, I get four events, but I should get eight (four for changing it to "12" and four for changing it to "123"). This is inconsistent with IntegerItem, which fires all four events immediately whenever the value is changed, and which does not require a change of focus.

                Here's my updated test case:

                Code:
                package test.client;
                
                import com.google.gwt.core.client.EntryPoint;
                import com.google.gwt.core.client.GWT;
                import com.smartgwt.client.widgets.form.DynamicForm;
                import com.smartgwt.client.widgets.form.events.ItemChangeEvent;
                import com.smartgwt.client.widgets.form.events.ItemChangeHandler;
                import com.smartgwt.client.widgets.form.events.ItemChangedEvent;
                import com.smartgwt.client.widgets.form.events.ItemChangedHandler;
                import com.smartgwt.client.widgets.form.fields.IntegerItem;
                import com.smartgwt.client.widgets.form.fields.SpinnerItem;
                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;
                
                public class Application implements EntryPoint {
                
                    public void onModuleLoad() {
                        GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() {
                            public void onUncaughtException(Throwable t) {
                                System.err.println("--- UNCAUGHT EXCEPTION ---");
                                t.printStackTrace();
                            }
                        });
                
                        SpinnerItem spinnerItem = new SpinnerItem();
                        spinnerItem.setName("SpinnerItem");
                        spinnerItem.addChangeHandler(new ChangeHandler() {
                            @Override
                            public void onChange(ChangeEvent changeEvent) {
                                System.out.println(changeEvent.getItem().getName() + " value about to change to '" + changeEvent.getValue() + "' ((FormItem)ChangeEvent)");
                            }
                        });
                        spinnerItem.addChangedHandler(new ChangedHandler() {
                            @Override
                            public void onChanged(ChangedEvent changedEvent) {
                                System.out.println(changedEvent.getItem().getName() + " value changed to '" + changedEvent.getValue() + "' ((FormItem)ChangedEvent)");
                            }
                        });
                
                        IntegerItem integerItem = new IntegerItem();
                        integerItem.setName("IntegerItem");
                        integerItem.addChangeHandler(new ChangeHandler() {
                            @Override
                            public void onChange(ChangeEvent changeEvent) {
                                System.out.println(changeEvent.getItem().getName() + " value about to change to '" + changeEvent.getValue() + "' ((FormItem)ChangeEvent)");
                            }
                        });
                        integerItem.addChangedHandler(new ChangedHandler() {
                            @Override
                            public void onChanged(ChangedEvent changedEvent) {
                                System.out.println(changedEvent.getItem().getName() + " value changed to '" + changedEvent.getValue() + "' ((FormItem)ChangedEvent)");
                            }
                        });
                
                        final DynamicForm form = new DynamicForm();
                        form.setMargin(10);
                        form.setFields(spinnerItem, integerItem);
                        form.addItemChangeHandler(new ItemChangeHandler() {
                            @Override
                            public void onItemChange(ItemChangeEvent itemChangeEvent) {
                                System.out.println(itemChangeEvent.getItem().getName() + " value about to change to '" + itemChangeEvent.getNewValue() + "' ((DynamicForm)ItemChangeEvent)");
                            }
                        });
                        form.addItemChangedHandler(new ItemChangedHandler() {
                            @Override
                            public void onItemChanged(ItemChangedEvent itemChangedEvent) {
                                System.out.println(itemChangedEvent.getItem().getName() + " value changed to '" + itemChangedEvent.getNewValue() + "' ((DynamicForm)ItemChangedEvent)");
                            }
                        });
                        form.draw();
                    }
                
                }
                Last edited by ispringer; 31 Oct 2011, 08:28.

                Comment


                  #9
                  This is a fix for your problem that I used.

                  The ChangeOnKeypress is set to false for the SpinnerItem

                  so: spinnerItem.setChangeOnKeypress(true);

                  This will change the value on a key press. Watch for null values when pressing backspace or delete.

                  Hope this helps

                  Comment

                  Working...
                  X