Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is UI data binding in Java more trouble than it is worth?

I've spent some time recently learning and attempting to use various Java data-binding tools such as JGoodies, GlazedLists, JSR-295, etc. The problems that I've been trying to solve are not that difficult, however the amount of code I've had to write in support of the binding process heavily outweighs any simplifications it provides.

I've found that the tools provided don't lend themselves to anything other than trivial composition and extension (GlazedLists in particular provides a great set of tools, but is far too complicated a system to extend).

I really like the idea of data-binding, however it seems to be deeply flawed as it stands. Am I missing something?

like image 341
timpatt Avatar asked May 05 '11 06:05

timpatt


People also ask

What is data binding in Java?

Data binding is the process that couples two data sources together and synchronizes them. With data binding, a change to an element in a data set automatically updates in the bound data set.

What are the data binding methods?

In computer programming, data binding is a general technique that binds data sources from the provider and consumer together and synchronizes them. This is usually done with two data/information sources with different languages, as in XML data binding and UI data binding.

What is data binding with example?

Data binding is the process of connecting a display element, such as a user interface control, with the information that populates it. This connection provides a path for the information to travel between the source and the destination. For example, consider the main window on your favorite browser.


2 Answers

All my presentations regarding desktop patterns and data bindings contain a strong warning regarding the problems developers face with automatic data binding. And I suggested to consider using a desktop pattern like MVP that is quite easy to use and does not need a binding.

The problems with binding are the many implicit operations; these help but are difficult to understand if something unexpected happens, and only a few developers can debug and solve problems in a third-party binding chain.

But during that past three years less programmers in the projects I worked in actually faced problems. And so I tend to say that binding is not such a big problem any more.

like image 64
Karsten Lentzsch Avatar answered Sep 20 '22 15:09

Karsten Lentzsch


If your app is trivial you it really doesn't matter if you do binding or if you write your listeners one by one.

If you app has made progress for some man months, introducing binding after the fact will cause some pain. The same is true for pretty much every (helpful) technology. Large amounts of the pain might come from the mess you took for granted before.

If you use binding correctly you might gain complete separation of gui and gui behavior. This in turn means

  • you can test you presentation model (the stuff you bind your components to) without swing, without EDT, just with plain unit tests.
  • you can test you binding with simple test involving only very few Swing Components

If you try to reach the same without a binding framework you'll end up writing your own binding framework.

There is a serious problem though IMHO about binding in the java world. It forces you to write getters + setter with PropertyChangeSupport, which is tedious and error prone. I don't see a realistic way to fix it in Java, but other languages (think Scala) offer interesting oportunities here. See my last blog post if you are interested: http://blog.schauderhaft.de/2011/05/01/binding-scala-objects-to-swing-components/

like image 31
Jens Schauder Avatar answered Sep 17 '22 15:09

Jens Schauder