Validation in Vaadin

Well I said In the previous Post we will study about the validators in this post .

for example

let us take an example of having form named first name last name email and password

Now what we require is that we have to validate first name, last name and  email how to do that..?

well here is the solution not making and generating the previous program again but just will explain in short for vaadin we don't use regular expression as we did in other languages to validate the field neither we have to make the property as we generated in HTML but here there is the different approach..!!

example

TextField fnm;
fnm=new TextField(enter your first name); //this field must be validated

//validation code below

fnm.addValidator( new StringLengthValidator(
                    "Must be between 2 and 10 characters in length", 2, 10, false));


//first you register the fnm to validator in it you set Constraint by String validator so when the mouse pointer will Hover up in that field it will show the  message you have set in it ..!! the message is "Must be between 2 and 10 characters in length" you can set any message in it the style would be set to default of the view message next argument is min number of character  and next to it you have max no of character and at last you have whether to enable or disable...!!


Another we have an Email validator for it you just have to

TextField email = new TextField("Email");

 email.addValidator(new EmailValidator("Invalid e-mail address"));

Here comes the eaiser concept we all have faced difficulties in writing regular expression for email quit tricky right...!!

But here theres simple just you have to instantiate and pass any message you want in it..!!


Note :Both are TextField but the validations applied are different..!! 

For password of 8 letters you can use the same validator as in fnm because password field works the same as TextField..!!



  

Comments

Popular posts from this blog

Navigation in Vaadin.

Drag and drop items from one Grid to another

State space search / blocks world problem by heuristic approach /TIC TAC TOE