« Return to Thread: Binding question

Binding question

by Rabson, Hugo SPC MIL USA USARPAC :: Rate this Message:

Reply to Author | View in Thread

Hi all,

I've got a "beans binding" question that's been bugging me for a while. I
hope someone can open my mind & explain the "best practice" answer to me.

Let's say you create two SQL tables (Persons and Cats), bind Persons to a
JTable of the same name, and do some OneToMany/ManyToOne annotations so that
each Person record has a List<Cats> cats available.

This isn't hard but I've not yet figured out how to bind the resultant list
to another JTable.

If it were just the person's name, I would bind it to a text field with
${selectedItem.personName}. The getter and setter getPersonName() and
setPersonName() exist, NetBeans offers personName as a bindable element, and
so on.

But of course it isn't a string. It is a list. I've created the getters and
setters:-

List<Cats> getCatsList()
void setCatsList(List<Cats> cats)

NetBeans offers to bind the jtable to catsList just as easily as if it were
a string but I get a cast exception at runtime.

My ideas are:-
1. I *could* use a converter to go back & forth between the list and the
jtable. I'm not sure if that would solve the CastException error I get at
runtime, though.
2. I *could* abandon binding (of the subtable) altogether; instead, I could
make the main (Persons) table reset and repopulate the Cats table each time
the user clicks on a line in the Persons table. However, I think Beans
Binding would be more elegant & easier to maintain.
3. I could find a RAD suite that does this stuff for me.

Thank you in advance for any advice you can offer. I am loving Java but I'm
feeling I need a degree in Computer Science to write a useful program. :)
All pointers are appreciated.

-Hugo


 « Return to Thread: Binding question

LightInTheBox - Buy quality products at wholesale price