This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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
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
Joined: Sep 21, 2003
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
... 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
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
Joined: Sep 21, 2003
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