• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question about booking a flight

 
Titus Campbell
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Background:
In the Data Client
Object[][] search(String criteria);
Int bookFlight( Object rec, int seats);
Problem:
When the client UI performs a search (calls the search(String criteria) method of the data client), the data client returns Object[][] instead of DataInfo[] because the UI shouldn�t have to know anything about the database implementation. All is well so far.
The problem occurs when a user selects a flight and tries to book a seat (calls the bookFlight method of the data client). Some form of flight identification has to be passed from the UI to the DataClient so that the correct record is updated. Since I only have a table of Objects, how do I know which column contains the flight number? There has got to be a better way of identifying the desired column then hard coding a column index or a column name into the UI.

Here is the idea I came up with to solve this problem.
In the �Object[][] search(String criteria)� method of the DataClient, I load the return array as follows.

therefore, along with the record data, the first row contains column names and the first column contains a reference to the original DataInfo object

My tablemodel subclass essentially hide the first column for displaying purposes but provide an access method (getKeyObj[int row]) to get it.
When the user selects a row and hits the book button, simply call the bookFlight method of the Data Client and pass in MyTableModel.getKeyObj(selectedRow) and the number of desired seats.
Does that solution make sense? Has anyone else encountered this problem? How did you handle it?
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks fine. I've seem people also handle the problem by returning a custom TableModel object to the GUI, which contains the id you're talking about explicitly. In this paradigm, the DataClient is a full fledged service provider to the GUI. However, I think you're approach works also.
All best,
M, author
The Sun Certified Java Developer Exam with J2SE 1.4
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic