Reputation: 2206
I have a bean to validate using jsr-303 but the BIndingResult returns no error. every time it returns to the success view
My Bean is
public class User
{
//@NotNull
private int userId;
@NotNull
@Size(min=3,max=100)
private String userName;
@NotNull
@Size(max=60)
private String userFullName;
}
my controller is
@RequestMapping(value="/user")
@Controller
public class UserController{
@RequestMapping(value="/create",method=RequestMethod.GET)
public String createUserForm(Map model)
{
model.put("user",new User());
return "createUserForm";
}
@RequestMapping(value="/create",method=RequestMethod.POST)
public String createUser (@Valid @ModelAttribute("user") User user,BindingResult result,Map model)
{
if(result.hasErrors())
{
return "createRmsUserForm";
}
else
{
model.put("User",user);
return "redirect:/home";
}
}
}
Upvotes: 2
Views: 3114
Reputation: 15204
Why you show another page when error occurs? Try to return user to the same page: in your case createUserForm
instead of createRmsUserForm
.
Upvotes: 1
Reputation: 12942
if you are using maven
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.0.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.2.0.Final</version>
</dependency>
Upvotes: 2
Reputation: 597016
dispatcher-servlet.xml
. <mvc:annotation-driven />
is the easiest way.Upvotes: 6