• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not refreshing table in network mode

 
rinke hoekstra
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi List,
(urlybird 1.1.1)

I noticed something strange with my book method.

I've been developing while testing in standalone mode, and all works fine: after booking the table nicely refreshes, and shows the booking member in the final field of the record which was just booked.

However, now I tested it out in Server/client mode, and the table does NOT refresh after the booking is done. I've tested it on the same machine using localhost as the server, and on a different machine in the network as server.

I used fireTableDataChanged() after the book method to update the table, but it is quite unclear to me what this method does exactly. Can anyone clarify this? Apparantly it does not work over a network??

The alternative is of course just to reload everything with table.setModel(..), but that seems much rougher than refreshing, and by the way, it causes problems with keeping the selection.
 
Alex Belisle Turcot
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

you could start by checking if your table model really does contains up to date records. If so, then it could be a refreshing problem.

But if it does not (which I would suspect), the problem could rather be that your are not retrieving the records from the database in network mode.

Could be a million things, maybe an exception is thrown (your not handling it or printing the stack). Work it from your data model up to the database in debug mode.

FireTableDataChanged :
http://coding.derkeiler.com/Archive/Java/comp.lang.java.programmer/2007-05/msg00330.html
http://forum.java.sun.com/thread.jspa?threadID=5169124&messageID=9649176
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, partner.

However, now I tested it out in Server/client mode, and the table does NOT refresh after the booking is done.


Unfortunately, this is correct
The thing is, after you book a room, the database on the server will be up-to-date, but the records that the clients have on their table models won't.

Here's what the fireTableDataChanged() does:

"Notifies all listeners that all cell values in the table's rows may have changed. The number of rows may also have changed and the JTable should redraw the table from scratch. The structure of the table (as in the order of the columns) is assumed to be the same."

So, right after adding values to your table model, the table won't refresh until you call this method. And even if the clients call this method, nothing is going to happen, until the table model is updated. You need to update your table model with the latest data from the database server, then call fireTableDataChanged().
 
Chih-Wei Lee
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use Observer and Observable.
I used this to refresh the table after booking a record.
Both network mode and standalone mode work well.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic