Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8119521

Invalidation listener only called once for bidirectionally bound properties

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • fx2.1
    • fx2.0.2
    • javafx

    Description

      In the code snippet below value1 is bidirectionally bound to value2 which is then bidirectionally bound to value3. An Invalidation listener is added to value3. When value1 is set for the first time the invalidation listener is called. The invalidation listener is not called for subsequent changes to value1. It is interesting to note that when value3.get() is called from inside the invalidation listener it seems to fix the problem.


      //---------------------------------------- CODE --------------------------------------------
      package fxtest;

      import javafx.beans.InvalidationListener;
      import javafx.beans.Observable;
      import javafx.beans.property.SimpleStringProperty;
      import javafx.beans.property.StringProperty;

      public class InvalidationListenerNotCalled {
      private static int count = 0;
      public static void main(final String[] args) {
      final StringProperty value1 = new SimpleStringProperty();
      final StringProperty value2 = new SimpleStringProperty();
      final StringProperty value3 = new SimpleStringProperty();
      value1.bindBidirectional(value2);
      value2.bindBidirectional(value3);
      value3.addListener(new InvalidationListener() {
      @Override
      public void invalidated(final Observable observable) {
      // Insert the following line to receive invalidation calls
      //value3.get();
      count++;
      }
      });
      System.out.println("count --> Expected: 0 - Actual: " + count);
      value1.setValue("123");
      System.out.println("count --> Expected: 1 - Actual: " + count);
      value1.setValue("456");
      System.out.println("count --> Expected: 2 - Actual: " + count);
      }
      }

      Attachments

        Activity

          People

            mheinrichs Michael Heinrichs (Inactive)
            aswanepoejfx Abraham Swanepoel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: