lundi 30 mars 2015

@Size and @Pattern annotation are not working in Spring MVC

Added the below jar's to my lib folder in WEB-INF:



  • classmate-1.0.0

  • javax.el-2.2.4

  • javax.el-api-2.2.4

  • jboss-logging-3.1.3.GA

  • validation-api-1.1.0.Final


The pieces of code I added are:


From model object:



public class UserDetails {

@Pattern(regexp="(^0-9}*")
private String userName;

@Size(min=2,max=10)
private String firstName;
private String lastName;
private String emailId;
private ArrayList<String> accountType;
private ArrayList<String> gender;

@Size(min=2,max=10)
private Long accountNo;


FromController class:



@RequestMapping(value = "/UserAccount.html", method = RequestMethod.POST)
public ModelAndView userAccountForm(
@Valid @ModelAttribute("user") UserDetails user,
BindingResult result) {

if (result.hasErrors()) {
ModelAndView model1 = new ModelAndView("LoginForm");
return model1;
}

ModelAndView model1 = new ModelAndView("UserAccount");
return model1;
}


My dispatcher servlet has



<mvc:annotation-driven/>


Kindly let me know If I missed any basic thing.


Aucun commentaire:

Enregistrer un commentaire