Originally posted by Jean Robillard:
Are we responsible for validating the user input for meeting the given character set?
Interesting. I am in 2 minds about this.
At a "SCJD assignment" level, I think that trying to handle this is possibly going beyond requirements - it may be something that you document in your choices.txt file as being out of scope.
However in real life I would think that
you should be responsible for this, and furthermore I think you should be double checking - once at the GUI level to give the user immediate feedback that there is a problem, plus also at the database layer itself in case they scrap your GUI but keep your database layer.
Originally posted by Jean Robillard:
... If so, how ?
On the GUI side, I think you could possibly extend JTextField to only allow certain characters. I have an example in chapter 8 of my book, (page 247), however this is also discussed in the topic "
Book Number text field".
At the point where you are saving the data, I would be tempted to do a quick and dirty bit of coding. Something like:
This allows for the potential future growth of the system where fields other than the customer number may be saved. As long as the input string matches the same string recoded into US-ASCII then it will be saved.
There may be a more efficient way of handling this, however I have already spent more time just now than I originally intended - sorry.
Originally posted by Jean Robillard:
I instantiated a String with a given character set before saving to DB and did the same when reading from DB, but doing so alone will not validate user's input or throw any exception. Worse yet, it went ahead & saved the foreign words that I entered into DB, and it totally corrupted the DB and rendered the application useless.
I think this is a good reason for doing validation!
Originally posted by Jean Robillard:
So, is there any point in the assignment instruction to use certain character set (other than the default)
Well the assignment would be an order of magnitude harder if you had to have the ability to change records where the field lengths are no longer fixed.
Regards, Andrew