Re: Beans binding + disappointment
On 6/22/2010 6:40 AM, Hole wrote:
Hi There,
I was looking for a solution to bind Swing widgets and beans (or list
of beans).
Surprisingly, I've found some projects on dev.java.net that are
completely overlapped and it's not clear which project is active or
not (as for JSRs).
In Java 6 SE, there's no bean binding implementation.
So, is anyone aware of a standard, stabilized and wide-used by java
community for bindings?
In particular, I was looking for some patterns/libraries that allows
to bind directly a JTable and a list of beans. And, for instance,
retrieve the bean which corresponds to a selected row in a JTable and
binding properties of this selected bean to text properties of some
JLabels (imagine a panel with detailed info about the selected
object).
BTW, I'm really disappointed about this mess around...
Thanks in advance,
--
-d
The trouble with this is that the JTable Model is event driven, where
user-beans need a lot of work to add event notification for property
modification. I've tried to write such a library several times, and
always run into the same issues. Also, custom renders and editors for
bean properties aren't easy to handle in certain cases.
Also note, that while it is certainly a common use-case to have a table
which is bindable to a list of beans, the JTable is much more flexible
(think spread-sheet, or special "command" rows, etc...), and can have
different "sections" of the same table be treated differently.
It *is* possible to create an object which implements both
java.util.List and javax.swing.ListModel, the trouble comes from mutable
objects. IF the object mutates, technically an event needs to be fired.
In order to handled that, the beans have to register listeners. A lot
of boiler-plate code. Yarg.
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>