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: Hardcode or using getHeaderNames? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "NX: Hardcode or using getHeaderNames?" Watch "NX: Hardcode or using getHeaderNames?" New topic
Author

NX: Hardcode or using getHeaderNames?

Jonathan Liu
Greenhorn

Joined: Aug 21, 2003
Posts: 26
Using getHeaderNames this kind of method can read the field name from db file as Header Name in JTable. But the detailed descriptions are not stored in db file which can be useful tooltip, so if I want tooltip, I have to hardcode the View code, this is what I am trying to avoid of .
Thinking about MVC,MVC is used to sepearte business logic with presentation and control. View is responsible for presentation and should be made UI friendly, so I think for View, friendly UI carries more weight than dealing with potential field name changes.
Which one do you perfer, my friends?
Please give me some comments.
Javini Javono
Ranch Hand

Joined: Dec 03, 2003
Posts: 286
Hi,
I'm not sure I understood your question entirely, but here goes:
For example:
* given field name in file is "name"
* and detailed description to use in tool tip is
"The name of the hotel this vacancy record relates to"
which is not in the database file.
I don't see any way the string "The name of the hotel this vacancy record relates to"
can get into your program unless you "hard code it" (either literally or
have it available in a file, perhaps a keyed file (see Properties class), i.e
the properties file would have this line:
name=The name of the hotel this vacancy record relates to
If the long definition of "name" is in a properties file, at least it is
more isolated, but it is still, at some point, typed in by a human.
Aside: Assume, and this may or may not be a consideration in your
design: that in the future you may have more than one database file.
Then, call the current database file "DB1" and then in the properties
file you can say:
DB1.name=The name of the hotel this vacancy record relates to
Now, refering to the simpler example above for the properties
file:
name=The name of the hotel this vacancy record relates to
we have, of course, "hard coded" the string "name". What you
can do, is after reading the header information, scan the properties
file to make sure every name, such as "name", is defined, and if not
notify the developer that the database field labels are not consistent
with the properties file.
Note that even though we hard-coded the string "name" in the
properties file, we are doing this because we are writing a
simple translator, and the definition of "name" is
"The name of the hotel this vacancy record relates to"
which has to be defined somewhere.
Thanks,
Javini Javono
P.S.
My program will not hard code the field names, such as "name",
but instead, read them from the database file.
[ January 14, 2004: Message edited by: Javini Javono ]
Jonathan Liu
Greenhorn

Joined: Aug 21, 2003
Posts: 26
Thank you,Javini
For simplicity, we can read the header name from the db file, without caring about Tool tip.
I just wonder from the perspective of MVC, shouldn't we make the GUI more friendly ? So does this mean hard code is better?
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Hi Jonathan,

For simplicity, we can read the header name from the db file, without caring about Tool tip.

In addition, you can provide a mapping inside the properties file.
If there is a mapping, it displays the "nick name" of the header, otherwise, displays the original name.
e.g. inside the properities file, we have:

If we found such mapping, we use Hotel Name inside the JTable heading. If not, we use name.

So does this mean hard code is better?

Why need so? You can put the field names inside the Transfer Object (TO), and when the server send the results back, the JTable can obtain the header from TO easily.
Nick.


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Jonathan Liu
Greenhorn

Joined: Aug 21, 2003
Posts: 26
So, you guys all use ToolTip?
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Hi Jonathan,

So, you guys all use ToolTip?

I have used ToolTip.
Nick.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NX: Hardcode or using getHeaderNames?
 
Similar Threads
B&S Initial thoughts about the DB and GUI
Future Proof Design?
File Upload
wat is MVC architecture ?
Need to add linebreak in label of f:selectItems