Java Server Faces, SQL SERVER and CHAR FIELDS
I have modified the excellent JTDS driver to strip the spaces from CHAR FIELDS so that Java Server faces controls do not get confused when fields are of different lengths and also when you go to edit a field you don’t get a pile of spaces at the end of the text.
Well I have a project where the people who originally designed the database were obviously monkeys. So they used CHAR fields throughout the database. But not all the same size, for example:-
TABLE 1 (SERVICE CODES) SERVICE CODE CHAR 2 JI
Then in an other table
TABLE 2 SERVICE CODE CHAR 50
This means that if you create a drop down box on a page with the service code list it would be padded and would not match the other table. I initially started modifying the SQL code to CAST service code as a CHAR to match the other one. Since there were 100 odd tables this meant masses of extra work to use Java Server Faces.
The other problem is that editing fields have extra spaces at the end of the data – what a nightmare.
So I pulled down the open source JTDS driver and rewrote it to trim all spaces from CHAR fields, thus making JSF work right and solving my SPACE problem.
The files are here
Note if you download and use this you do so at your own risk, no warranty, implied or otherwise is provided for this software.
Note 2: if you were using an OLD jdts driver you will need to remove the references from the SERVER as well as NETBEANS and use this new one – I might get round to renaming the driver to something else but if you find there are spaces where there should not be its probably because you are running the standard driver not the new one.
Note 3: If you just want the driver its in the “dist” subdirectory, you need the LIB folder as well.
Note 4: If you publish a project using this driver and modify the driver then publish it again, NB won’t change the driver on the glassfish server if it has the same name, so you’ll have to copy it over yourself.