Alarmnummer
Mar 1st, 2005, 08:43 AM
I have a few questions about validation.
1) If the controller has validated the input should the service check the input again? The service should not rely on the fact that the controller has validated the input imho.
2) There are different levels of validation. There are some constraints that apply for every instance of a class, eg.. the age of a employee should never be smaller than 0, or greater than 150. But there are also other constraints.. an employee should not be able to edit his own wage, although wage is part of every employee. So you need on top of the class validation some kind ofrolebased validation. If have checked the "J2EE Design and Development" book, but nothing was mentioned there. A simple solution would be to chain the validators, but I find it strange I haven`t seen it yet.
3) The validator is not bound to the entity. So if I set some fields in a service, should the the service validate with a Validator aswell? How does the validator integrate with normal business logic? Or should normal business logic not rely on a validator and should it be hard coded?
1) If the controller has validated the input should the service check the input again? The service should not rely on the fact that the controller has validated the input imho.
2) There are different levels of validation. There are some constraints that apply for every instance of a class, eg.. the age of a employee should never be smaller than 0, or greater than 150. But there are also other constraints.. an employee should not be able to edit his own wage, although wage is part of every employee. So you need on top of the class validation some kind ofrolebased validation. If have checked the "J2EE Design and Development" book, but nothing was mentioned there. A simple solution would be to chain the validators, but I find it strange I haven`t seen it yet.
3) The validator is not bound to the entity. So if I set some fields in a service, should the the service validate with a Validator aswell? How does the validator integrate with normal business logic? Or should normal business logic not rely on a validator and should it be hard coded?