Announcement

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

    SelectItem.setValue(xx) triggers ChangeHandler

    smartgwt-3.1d

    I know this question was asked a few years ago - I'm hoping there is a solution today (or perhaps I missed it): I can't seem to find a programattic way of causing SelectItem ChangeHandler to fire. I do see fireEvent, but I see no examples of how to use it.

    From a testing point of view, it's escpecially painful to not be able to have ChangeHandler fire.

    Thank you.

    #2
    By design, ChangeHandlers fire for user actions, not programmatic changes. Otherwise it's very easy to get into infinite loops.

    Use Selenium or similar tools for automated testing.

    Comment


      #3
      I understand the infinite loop issue - I believe Swing controls are at risk because of this reason. Acknowledging that ChangeHandlers are designed to be only user driven, can fireEvent do what I need to do (Selenium is a bit heavy weight)?

      I have a form that has change handlers, closing/opening SectionItems as well as enabling/disabling TextItems. In the context of CRUD, I wanted to be able to treat Create and Update the same - Create is user driven, but filling in the form from the Update is programmatic. In both cases, I should expect the same visually. For example (and attached), Create (user driven) is going to work perfectly. However, when I load a record from the DB, in order for me to be able to share the identical it makes for for less elegant code (you end up gutting your anonymous methods).

      save.addChangeHandler(new ChangeHandler() {
      public void onChange(ChangeEvent event) {
      boolean on = (Boolean) event.getValue();
      pass.setDisabled(!on);
      login.setDisabled(!on);
      pass.setRequired(on);
      login.setRequired(on);
      if (on) {
      form.focusInItem(login);
      }
      }
      });
      Attached Files

      Comment


        #4
        Calling the same code in both circumstances does not seem to be longer, not would we recommend synthetic events as a way to drive a very ordinary user interaction - that would not be expected by other developers reading the code later.

        Comment

        Working...
        X