aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX: Record num in TableModel 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 "NX: Record num in TableModel" Watch "NX: Record num in TableModel" New topic
Author

NX: Record num in TableModel

Chris Harris
Ranch Hand

Joined: Sep 21, 2003
Posts: 231
Hi all,
I am looking for some advice. Should I display the record number in the client gui? Is was not planning to but if i don't I need to work out how the record the user selects in the table matches a record number. I was thinking of storing the record number within my ContractorTableModel but not show it to the user. Is this the way it should be done or is it just fine to show the number to the user?
Thanks
Chris


SCJP 1.2, SCWCD, SCBCD
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
I can't see any reason to show it to the user; they don't need to know. Certainly your program would need to keep track of the relationship between table rows and record numbers, however.


"I'm not back." - Bill Harding, Twister
Vlad Rabkin
Ranch Hand

Joined: Jul 07, 2003
Posts: 555
Hi Cris,
I was thinking of storing the record number within my ContractorTableModel but not show it to the user.

I have another assignment, but the same problem. I did it, as you described:
keep id in TableModel, but don't show it the table view.
Best,
Vlad
Chris Harris
Ranch Hand

Joined: Sep 21, 2003
Posts: 231
Hi all,
I came up with the idea of storing the record number within the tableModel with out showing it to the user. But how? I could store it in a Map as the number as the key and the contractor as the value. But how can I work out the record number from the getSelectedRow. As you are all aware this will return the record number (Within the table) that has been selected. This number is not related to the contractor record number.
Or is there a way of not showing a column to the user?
Can someone please point me in the right direction.
Thanks
Chris
Wilder C Rodrigues
Ranch Hand

Joined: May 03, 2003
Posts: 107
Hi,
I sent my project yesterday and I put the record # in the JTable. Is it bad?
tx
Wilder


SCEA Part I, SCAJ, SCPJ, SCDJ, SCWCD, SCBCD, SCMAD<br /> <br />"The significant problems we face can not be solved at the same level of thinking we were at when we created them." - Albert Einstein
Paul F. Williams
Greenhorn

Joined: Nov 04, 2003
Posts: 6
Originally posted by Wilder Rodrigues:
Hi,
I sent my project yesterday and I put the record # in the JTable. Is it bad?

I hope not. You have lots of flexibility in how you do things. As long as you can justfiy your decisions-- and as long as those decisions don't violate the requirements-- go for it.


Paul F. Williams<br />SCJP July 2003
Paul Tongyoo
Ranch Hand

Joined: Sep 30, 2003
Posts: 91
Originally posted by Chris Harris:

...
I came up with the idea of storing the record number within the tableModel with out showing it to the user.
...

Maybe it helps to not think of "storing the record number" but instead to think of "keeping track of the index to the selected row"? And keeping track of this index is easiest if the return value of table.getSelectedRow() equals the index of the matching record in the data structure that contains your data file find/search results that are fed to your GUI layer.
Oh, and it helps to stick to the responsibilities of each MVC role to make sure you're putting the logic in the correct objects (ie, it'll help you decide if some of your tableModel code should really be in your Controller class). Check out this great picture explaining the responsibilities of each role on java.sun.com:
http://java.sun.com/blueprints/patterns/MVC-detailed.html
(in the middle, with the three gray boxes)
HTH

Paul
[ November 04, 2003: Message edited by: Paul Tongyoo ]
[ November 04, 2003: Message edited by: Paul Tongyoo ]

Sun Certified Java Web Component Developer for J2EE v1.4<br />Sun Certified Java Developer for J2SE v1.4<br />Sun Certified Java Programmer for J2SE v1.4
Kerry Friesen
Greenhorn

Joined: Oct 10, 2003
Posts: 23
Originally posted by Chris Harris:
Hi all,
I came up with the idea of storing the record number within the tableModel with out showing it to the user. But how?

Hi Chris,
What I've done for my assignment is keeping the record number as a hidden column in the table model. If you use the following code:

This will remove the table column from the view, not the model (where "ID" is the name of the column for your record number).
Hope this helps.
Cheers,
Kerry


Kerry Friesen<br />SCJP 1.2<br />SCJD
Chris Harris
Ranch Hand

Joined: Sep 21, 2003
Posts: 231
Thanks Kerry and Paul,
You have provided me with two very possible solutions to my problem.
1) Change the getSelectedRow - very nice solution but would require a little more work then just removing the column for the table.
2) Remove the column for the view - less work and shows a clear understanding between the view and the model.
The question is which one is more relevent for the assigment. Or to put it another way, which one would I get more marks for?
To be honest I don't really think I would lose marks depending on this choice.
Chris.
Chris
 
Consider Paul's rocket mass heater.
 
subject: NX: Record num in TableModel