2 Replies Latest reply on Jul 5, 2013 4:33 PM by Andipa

    Does Bindings.select not work with primitives properties like StringProperty etc?


      My code works when I use an ObjectProperty<String>, it however doesn't work when I use a StringProperty instead.


      Don't know if this behaviour of Bindings.select is a bug or expected.


      Here's the SSCCE:


      The printout is:

      ObjectProperty<String> -> ObjectProperty<String>: abc

      StringProperty -> StringProperty: null

      StringProperty -> ObjectProperty<String>: null


      I would expect all cases to print "abc" though


      import javafx.beans.binding.Bindings;
      import javafx.beans.property.ObjectProperty;
      import javafx.beans.property.SimpleObjectProperty;
      import javafx.beans.property.SimpleStringProperty;
      import javafx.beans.property.StringProperty;
      public class SelectBindingTest {
          public static class A {
              private StringProperty comment = new SimpleStringProperty(this, "comment");
              private ObjectProperty<String> commentObj = new SimpleObjectProperty<>(this, "commentObj");
              String getComment() {
                  return comment.get();
              StringProperty commentProperty() {
                  return comment;
              void setComment(String comment) {
              public String getCommentObj() {
                  return commentObj.get();
              public ObjectProperty<String> commentObjProperty() {
                  return commentObj;
              public void setCommentObj(String commentObj) {
          public static class B {
              private ObjectProperty<A> member = new SimpleObjectProperty<>(this, "member");
              A getMember() {
                  return member.get();
              ObjectProperty<A> memberProperty() {
                  return member;
              void setMember(A member) {
          public static void main(String[] args) {
              B b = new B();
              A member = new A();
              final String expectedString = "abc";
      // this works
              SimpleObjectProperty<String> targetStringObjProperty = new SimpleObjectProperty<>("initialTargetText");
              targetStringObjProperty.bind(Bindings.<String>select(b.memberProperty(), "commentObj"));
              System.out.println("ObjectProperty<String> -> ObjectProperty<String>: " + targetStringObjProperty.get());
      // this doesn't work
              SimpleStringProperty targetStringProperty = new SimpleStringProperty("initialTargetText");
              targetStringProperty.bind(Bindings.selectString(b.memberProperty(), "comment"));
              System.out.println("StringProperty -> StringProperty: " + targetStringProperty.get());
      // this doesn't work either
              targetStringObjProperty = new SimpleObjectProperty<>("initialTargetText");
              targetStringObjProperty.bind(Bindings.<String>select(b.memberProperty(), "comment"));
              System.out.println("StringProperty -> ObjectProperty<String>: " + targetStringObjProperty.get());


      EDIT: sorry for the awful formatting. Can't seem to figure out how to properly insert blank lines.