2 Replies Latest reply on Sep 6, 2012 4:55 PM by Michael Hirsch

    Can I listen for a change in a bound field?

    Michael Hirsch Newbie

      I've been playing with the AutoBound annotation in the latest release, and I really like it.  It will eliminate a lot of annoying code.

       

      It's really nice to have the data and the UI automatically change together, but sometimes I want to know when the change happens.  Is there a way to listen for changes in bound variables? 

       

      For instance, if I have a text field tied to a "username" string in a class somewhere.  If the text field changes, so will the username, and vice versa.  But what if I want to know that the username has changed?  The change could be coming from either the UI or something programmatic.

       

      I suppose that in this case I can watch the text field for changes, but that seems to go against the idea of pulling my intelligence out of the UI and putting it back in the code.

       

      What I'd really like is to be able to register for changes in a bound variable.  Then it could come from either the UI or something else and I would be notified.

       

      Thanks,

       

      Michael

        • 1. Re: Can I listen for a change in a bound field?
          Christian Sadilek Master

          Hi Michael,

           

          Yes you can do that by registering propertyChangeHandler(s) with the DataBinder either for a specific property or for all properties of the bound model.

           

          E.g.

           

          {code}dataBinder.addPropertyChangeHandler(new PropertyChangeHandler() {

                @Override

                public void onPropertyChange(PropertyChangeEvent event) {

                  System.out.println(event.getPropertyName() + " changed to:" + event.getNewValue());

                }

          });{code}

           

          or

           

          {code}dataBinder.addPropertyChangeHandler("name", new PropertyChangeHandler() {

                @Override

                public void onPropertyChange(PropertyChangeEvent event) {

                  System.out.println("name changed to:" + event.getNewValue());

                }

          });{code}

           

          Cheers,

          Christian

          • 2. Re: Can I listen for a change in a bound field?
            Michael Hirsch Newbie

            Thanks Christian.  Looks like just what I was looking for.

             

            Michael