File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX: Where TableModel goes? -- Client GUI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "NX: Where TableModel goes? -- Client GUI" Watch "NX: Where TableModel goes? -- Client GUI" New topic
Author

NX: Where TableModel goes? -- Client GUI

Rick Lu
Ranch Hand

Joined: Mar 25, 2003
Posts: 47
HI,
In my design, two JComboBox (Views) are hooked with DataModel (Model) (client side) through listeners. Controller (Control) deals with all inputs from JComboBox and JTable, then directly save all changes in the DataModel (Model).
But the question is where I should put TableModel? I consider it as the part of Views in MVC. But according to this, I cannot hook it with DataModel (model), right?. And I have no idea how to update it by View ( bypass Controller or not???) ?
Any suggestion for this? Thanks.
Rick
Regards.


SCJD 1.4
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11479
    
  94

Hi Rick,
Originally posted by Rick Lu:
But the question is where I should put TableModel? I consider it as the part of Views in MVC. But according to this, I cannot hook it with DataModel (model), right?. And I have no idea how to update it by View ( bypass Controller or not???) ?

I agree with your idea of having the TableModel within the view.
You could have the View getting the updates from the Model and passing them on to the TableModel. Alternatively, if your Model is Observable, you could make your TableModel an Observer, and have it receive the updates directly.
Does this give you some ideas?
Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Rick Lu
Ranch Hand

Joined: Mar 25, 2003
Posts: 47
Thank you, Andrew.

You could have the View getting the updates from the Model and passing them on to the TableModel.

I think JTable is the View. But of course, I need a class (TableModel) that extends AbstractTableModel. My question is that how I can update TableModel by View? Did you mean directly getting updates from Model to JTable and passing them to TableModel? Or something else? I cannot understand this. Currently, the view - JTable gets everything from TableModel. Could you explain this from me? Confused.
Regards. Rick
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11479
    
  94

Hi Rick,
You have some class that sets up the TableModel and the JTable. That class could either pass updates from the Model to the TableModel, or it could register the TableModel as an Observer of the Model (in which case the TableModel will get the updates automagically).
Regards, Andrew
Rick Lu
Ranch Hand

Joined: Mar 25, 2003
Posts: 47
Hi Andrew,

You have some class that sets up the TableModel and the JTable. That class could either pass updates from the Model to the TableModel,

You mean "That class" is a part of Views? To me, the role of it is not clear. I think that's my problem. Is it a part of View?
or it could register the TableModel as an Observer of the Model (in which case the TableModel will get the updates automagically).

Yes, I currently use it and it works.
Thanks. Rick
Rick Lu
Ranch Hand

Joined: Mar 25, 2003
Posts: 47
I think I undertand your points now, Andrew. Thanks.
Rick
Regards.
 
jQuery in Action, 2nd edition
 
subject: NX: Where TableModel goes? -- Client GUI