Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8661895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:36:29+00:00 2026-06-12T16:36:29+00:00

Maybe I missunderstood JavaFX binding or there is a bug in SimpleStringProperty. When I

  • 0

Maybe I missunderstood JavaFX binding or there is a bug in SimpleStringProperty.

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”.

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;
        }       
    }
    }

Thanks for your help.

Best regards
Sebastian

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.

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
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:36:30+00:00Added an answer on June 12, 2026 at 4:36 pm

    Just figured out that there is provided the class JavaBeanStringProperty, which just fullfill my request.

    Using this code I can directly bind the value of my bean to a StringProperty (included setting and getting of my value to / from my Bean).

    binding = JavaBeanStringPropertyBuilder.create().beanClass(Model.class).bean(model).name("prop1").build();
    

    The only problem I found is that when you change the value of the model after setting the binding, there is no update e.g. in the TextField.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Maybe it's because of the dark outside, but I can't get this Position geom_text
Maybe this is a dumb question, but is there any way to convert a
Maybe I just can't figure out the right keywords to get an answer out
Maybe it's wrong but I always use this query for my app: cme_only =
Maybe this is a poor question, but, I can't find a tutorial or even
Maybe it's a newbie question, but is there a method in C/C++ to prevent
I would like to save a modified model, but I get Programming error -
Maybe I misunderstood the layout_weight parameter but I can't get it why something like
Maybe I misunderstood this but from what I read I may have several problems
Maybe this is a very simple question, but I just can not figure out.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.