Wikia

Planet JFX

Binding to a POJO

Talk2
119pages on
this wiki

Introduction Edit

At this time, JavaFX variables bound to a pure-Java object (POJO) will not automatically update as they should. This article describes one or more ways to get two-way binding working.

Problem Statement Edit

Original Thread

I want to get a JFX button to change state given a property
change in Java code. I can pass the new state into the script
but the binding does not work.


 

Possible Solution Edit

Create a JavaFX object, identical to the POJO. Add a variable named 'backer' for the original POJO. Each variable must have an 'on replace' that updates the value in the backer variable. The 'on replace' for the backer variable will give all the values, the values of the original POJO.

 

Example of the POJO:

package org.mydomain;
public class OriginalPojo {
    private String name;
    private Integer age;
    // getters/setters for all parameters
}

Example of the JavaFx object:

package org.javafx.mydomain;
public class JavaFxPojo {
    public-init var backer : org.mydomain.OriginalPojo on replace {
      name : backer.getName();
      age : backer.getAge();
    }

  public var name : String on replace {
    backer.setName(name);
  }
  public var age : Integer on replace {
    backer.setAges(age);
  }
}


Solution based on this thread.

 

Around Wikia's network

Random Wiki