title: Binding in JavaFX 2.0
body: <p>Maybe I missunderstood JavaFX binding or there is a bug in SimpleStringProperty.</p>
  
  <p>When I run this testcode my changed model value didn't get the new value. Test testBindingToModel fails. I thought my model should then be updated with the value of the TextField tf. But only the binding value of prop1Binding gets the value "test".</p>
  
  <pre><code>public class BindingTest {  
      private TextField tf;
      private Model model;
      private ModelBinding mb;
  
      @Before
      public void prepare() {
          tf = new TextField();
          model = new Model();
          mb = new ModelBinding(model);
          Bindings.bindBidirectional(tf.textProperty(), mb.prop1Binding);
      }
  
      @Test
      public void testBindingToMB() {
          tf.setText("test");
  
          assertEquals(tf.getText(), mb.prop1Binding.get());
      }
  
      @Test
      public void testBindingToModel() {
          tf.setText("test");
  
          assertEquals(tf.getText(), mb.prop1Binding.get());
          assertEquals(tf.getText(), model.getProp1());
      }
  
      private static class ModelBinding {
          private final StringProperty prop1Binding;
  
          public ModelBinding(Model model) {
              prop1Binding = new SimpleStringProperty(model, "prop1");
          }
  
      }
  
      private static class Model {
          private String prop1;
  
          public String getProp1() {
              return prop1;
          }
  
          public void setProp1(String prop1) {
              this.prop1 = prop1;
          }       
      }
      }
  </code></pre>
  
  <p>Thanks for your help.</p>
  
  <p>Best regards
  Sebastian</p>
  
  <p>EDIT:
  With this class I can set the value of the model directly. I will test this class in the next days and comment on this post with my result.</p>
  
  <pre><code>public class MySimpleStringProperty extends SimpleStringProperty {
      public MySimpleStringProperty(Object obj, String name) {
          super(obj, name);
      }
  
      public MySimpleStringProperty(Object obj, String name, String initVal) {
          super(obj, name, initVal);
      }
  
      @Override
      public void set(String arg0) {
          super.set(arg0);
          if (this.getBean() != null) {
              try {
                  Field f = this.getBean().getClass().getDeclaredField(this.getName());
                  f.setAccessible(true);
                  f.set(this.getBean(), arg0);
              } catch (NoSuchFieldException e) {
                  // logging here
              } catch (SecurityException e) {
                  // logging here
              } catch (IllegalArgumentException e) {
                  // logging here
              } catch (IllegalAccessException e) {
                  // logging here
              }
          }
      }
  }
  </code></pre>