jeeper
Feb 2nd, 2011, 08:09 AM
Hello,
Ive got one question regarding Bean Validation in Spring (with Spring MVC and Hibernate)
I was now researching some hours to find the best way to implement validation.
I have the following example.
- A User wants to register
- There is a register formular for username, email, validate email, password, validate password, accept-agb
- In the database the users data is saved in the table users(user_id, username, password, enabled), users_information(users_id, email, ....) and some other tables (authorities, salt...)
- At the moment I first check the data with java script, then I submit it to the server (the controller, they get the data with @RequestParam)
- Then I call methods of my own class RegistrationCheck, where I check if the username is free, the email is valid, the password secure, the emails typed in equal and so on!
- When the checks are successful, the user is registered (I use Hibernate for it)
Now I read of using FormObjects and Validation. Im a little bit confused what to do now. I already have the Hibernate Classes, which contain the restrictions I have set in database with the create table commands.
For example username not null, etc ... in the Hibernate Class: Users.java, the String username is annotated with @NotNull then.
Im not sure where the begin. Shall I write my own Validation Classes like public class UserToRegister implements Validator and set all values which are given in through the register-formular there and check them?
Or shall I extend the existing Hibernate Classes and add some more Annotations there? Im not sure what to do.
I need to write some checking methods by myself, I guess, because I need to check if the username is free and so on.
I would be glad if someone could give me a hint! :-) Thank you!
Ive got one question regarding Bean Validation in Spring (with Spring MVC and Hibernate)
I was now researching some hours to find the best way to implement validation.
I have the following example.
- A User wants to register
- There is a register formular for username, email, validate email, password, validate password, accept-agb
- In the database the users data is saved in the table users(user_id, username, password, enabled), users_information(users_id, email, ....) and some other tables (authorities, salt...)
- At the moment I first check the data with java script, then I submit it to the server (the controller, they get the data with @RequestParam)
- Then I call methods of my own class RegistrationCheck, where I check if the username is free, the email is valid, the password secure, the emails typed in equal and so on!
- When the checks are successful, the user is registered (I use Hibernate for it)
Now I read of using FormObjects and Validation. Im a little bit confused what to do now. I already have the Hibernate Classes, which contain the restrictions I have set in database with the create table commands.
For example username not null, etc ... in the Hibernate Class: Users.java, the String username is annotated with @NotNull then.
Im not sure where the begin. Shall I write my own Validation Classes like public class UserToRegister implements Validator and set all values which are given in through the register-formular there and check them?
Or shall I extend the existing Hibernate Classes and add some more Annotations there? Im not sure what to do.
I need to write some checking methods by myself, I guess, because I need to check if the username is free and so on.
I would be glad if someone could give me a hint! :-) Thank you!