aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Room ID in JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Room ID in JTable" Watch "Room ID in JTable" New topic
Author

Room ID in JTable

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi all,
There has been a lot of discussion concerning the primary key issue in the URLyBird assignment. I've decided to make rowID my primary key.
Outside the DataAdapter/DataFacade class rowID is irrelevant because I use a Room value object (see this topic) with a primaryKey attribute. So, the Room simply knows it's got a primary key, but it doesn't know that its value is a rowID.
The client displays Room objects in a JTable and my TableModel, thus, stores a List of Room objects.
Ok, that is context... here comes the question:
Is there any other way of retrieving the primary key of a selected room other than making the key a hidden table column? This would be almost as ugly as displaying the primary key as a regular column...
I thought about a tableRowIndex/primaryKey mapping, but since my table model is sortable this would only complicate matters.
If you've got a hint (or two cents as ranchers like to say ) please let me know.
Regards,
Marcel
[ April 26, 2004: Message edited by: Marcel St�r ]
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hhmmm, maybe I should rephrase my question?
How do you store the reference to the roomID which is needed for the booking on the client side?
I still don't see any other solution than the "hidden column" hack...
Regards,
Marcel
Denis Spirin
Ranch Hand

Joined: Mar 22, 2004
Posts: 72
Hi Marcel
I did that as follows:
1. Model gets data as Vector. Each element is array containing its ID.
2. Model copies data into two-dimensional array without primary key.
Thus we have one-to-one relationship between row number in array and element
position in Vector.
If you want to let user to sort table, you just sort data (with keys), copy them to Vector (with keys) and then to 2d array (without keys).
Regards


Regards<br /> <br />Ph.D.<br />SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJD 2
 
Consider Paul's rocket mass heater.
 
subject: Room ID in JTable