This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
did you define "orgName" field as String or Integer type?
I have it as Integer
You mean defined in the backing bean? It is a String and YES, when I changed this to an Integer field, my trim() space validation stopped working :-(
123 = passes. Validation never reaches my custom validator
ou812 = fails with message " : 'ou812' is not a number pattern. " validation never reaches my custom validator.
" " (that should be 9 spaces ) = passes... Never reaches custom validator, shows up as null in backing bean...
" 0 " (zero surrounded by 4 spaces on each side) = fails and, for some reason, DOES reach my custom validator
and the reason is that Integer will trigger the default converter. The default converter attempts to convert the whitespace string you enter into an Integer object and it ends up with null, and since it is not required, it passes validation.
The solution is to write a custom converter. In this same app, I now have a simple custom converter (both methods return simple strings) that short circuits JSFs default Integer converter and forces my Validator to run and fail to pass a string composed only of spaces. The following page gives a good explanation of how to write custom converters.