java - Bean Validation with Validator is not working - why? -


i' trying bean validation injecting validator in cdi-bean.

that's why i've written servlet injects validator property. problem im getting wrong results. example, says name , surname properties aren't allowed null although i've set them regular name , surnames.

did wrong?

here servlet:

@webservlet public class beanvalidationservlet extends httpservlet {     private static final long serialversionuid = 1l;     @inject     private validator validator;     @inject     private workemployee workemployee;      @override     protected void doget(httpservletrequest request,             httpservletresponse response) throws servletexception, ioexception {         printwriter writer = response.getwriter();          workemployee.getadresse().setpostalcode("8888");         workemployee.getadresse().setstreet("washington street");         workemployee.getadresse().setstreetnumber(98);         workemployee.getadresse().sethome("philadeplphia");         workemployee.setemployeeid(12);         workemployee.setname("john");         workemployee.setsurname("doeuuu");         writer.print("<h1> surname:" + workemployee.getsurname() + "<h1>");         set<constraintviolation<workemployee>> constraintviolations = validator                 .validate(workemployee);         (constraintviolation<workemployee> violation : constraintviolations) {             writer.print("<h1>" + violation.getpropertypath() + ": "                     + violation.getmessage() + "<h1>");             writer.print("<h1>" + violation.getrootbean() + "<h1>");             writer.print("<h1>-------------------------------<h1>");         }          set<constraintviolation<adress>> constraintviolations2 = validator                 .validate(workemployee.getadresse());         (constraintviolation<adress> violation : constraintviolations2) {             writer.print("<h1>" + violation.getpropertypath() + ": "                     + violation.getmessage() + "<h1>");             writer.print("<h1>" + violation.getrootbean() + "<h1>");             writer.print("<h1>-------------------------------<h1>");         }     } } 

and cdi-beans:

the worker-class:

@requestscoped public class worker implements workemployee{      @notnull     private string name;     @notnull     @size(min=5,max=15)     @pattern(regexp="doe")     private string surname;     @min(5)     @max(12)     private int employeeid;      @inject     @valid     private adress adresse;      @override     public string getname() {         return name;     }      @override     public void setname(string name) {         this.name = name;     }      @override     public string getsurname() {         return surname;     }      @override     public void setsurname(string surname) {         this.surname = surname;     }      @override     public int getemployeeid() {         return employeeid;     }      @override     public void setemployeeid(int employeeid) {         this.employeeid = employeeid;     }      @override     public adress getadresse() {         return adresse;     }      @override     public void setadresse(adress adresse) {         this.adresse = adresse;     } } 

the adress-class:

@requestscoped public class adress {  @pattern(regexp="^47269$") private string postalcode; @notnull private string street; @notnull @min(15) @max(99) private int streetnumber; @notnull @size(max=25) private string home;  public string getpostalcode() {     return postalcode; }  public void setpostalcode(string postalcode) {     this.postalcode = postalcode; }  public string getstreet() {     return street; }  public void setstreet(string street) {     this.street = street; }  public int getstreetnumber() {     return streetnumber; }  public void setstreetnumber(int streetnumber) {     this.streetnumber = streetnumber; }  public string gethome() {     return home; }  public void sethome(string home) {     this.home = home; } } 


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -