1 Reply Latest reply on Nov 20, 2013 12:24 PM by csa

    how to make @UiHandler annoted methods being called only after databing ?

    anthony.f

      Hi,

       

      I'm using Errai to make databinding on my application that uses GWT UiBinder.

      The databinding works well, but my UI needs to react to some events, such as ChangeEvent.

      Here is an exemple :

       

      @Dependent
      public class myView  {
        @Inject
        @Model
        Customer customer;
      
        @UiField
        @Bound(property = "partner")
        ListBox partnerListBox;
      
        @UiHandler("partnerListBox")
        public void initClientListBox(ChangeEvent event) {
        String partner = customer.getPartner();
        [...]
        }
      }
      

       

      The problem is that when my initClientListBox() method is called to handle the ChangeEvent, the ErraiDatabing has not updated the model yet.

      So I cannot use my model in that use case.

       

      Errai allows to register a PropertyChangeHandler :

       

       

      dataBinder.addPropertyChangeHandler("name", newPropertyChangeHandler() {

        @Override

        publicvoidonPropertyChange(PropertyChangeEvent event) {

          Window.alert("name changed to:"+ event.getNewValue());

        }

      });

       

      But I think this is a boilerplate code, it would have been great if there was an annotation like this :

       

        @PropertyChangeHandler("name")
        public void onPropertyChange(PropertyChangeEvent event) {
          Window.alert("name changed to:" + event.getNewValue());
        }
      

       

      But I didn't find an annotation like this in Errai.

      Consequently, I have no choice but to use directly the widget value, while I think using the model would be cleaner.

       

      Do you think there is an easy way to use the model value in such a use case ?

       

      Thanks

       

      cheers,

      Anthony

        • 1. Re: how to make @UiHandler annoted methods being called only after databing ?
          csa

          Hi Anthony,

           

          We discussed adding annotation based PropertyChangeHandlers here: [errai-dev] Declarative API for PropertyChangeHandlers in DataBinding

           

          It can be done of course but would require quite a few API additions (more annotations) to support all use cases. At the time we decided that it was probably not providing enough benefit? As you pointed out the PropertyChangeHandlers provide the guarantee that when fired the UI and model will have already been updated. So, you can definitely use them.

           

          In your case, however, you're using a UI change to trigger another UI change, if I understood correctly. So, using the widget values directly and have the model update automatically in the background might actually be more intuitive.

           

          Cheers,

          Christian