Can any one help with this problem?
I cant configure validation in spring project .
Entity class
<code>public class Employee {
@Size(min = 2,message = "Name must be minimum 2 symbols")
private String name;
@NotEmpty(message = "surname is required field")
private String surname;
}
</code>
<code>public class Employee {
@Size(min = 2,message = "Name must be minimum 2 symbols")
private String name;
@NotEmpty(message = "surname is required field")
private String surname;
}
</code>
public class Employee {
@Size(min = 2,message = "Name must be minimum 2 symbols")
private String name;
@NotEmpty(message = "surname is required field")
private String surname;
}
Controller class
<code>@RequestMapping("/showDetails")
public String showDetails(
@ModelAttribute("employee") @Valid Employee employee,
BindingResult bindingResult, Errors errors){
if(bindingResult.hasErrors()){ // bindingResult.hasErrors() always return false
return "ask-detail-view";
}else{
return "show-detail-view";
}
}
</code>
<code>@RequestMapping("/showDetails")
public String showDetails(
@ModelAttribute("employee") @Valid Employee employee,
BindingResult bindingResult, Errors errors){
if(bindingResult.hasErrors()){ // bindingResult.hasErrors() always return false
return "ask-detail-view";
}else{
return "show-detail-view";
}
}
</code>
@RequestMapping("/showDetails")
public String showDetails(
@ModelAttribute("employee") @Valid Employee employee,
BindingResult bindingResult, Errors errors){
if(bindingResult.hasErrors()){ // bindingResult.hasErrors() always return false
return "ask-detail-view";
}else{
return "show-detail-view";
}
}
pom.xml
<code><dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>8.0.1.Final</version>
</dependency>
</code>
<code><dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>8.0.1.Final</version>
</dependency>
</code>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>8.0.1.Final</version>
</dependency>
jsp page
<code>
<from:form action="showDetails" modelAttribute="employee">
Name<form:input path="name"/>
<form:errors path="name" />
<br>
<br>
Surname<form:input path="surname"/>
<form:errors path="surname" />
<input type="submit">
</from:form>
</code>
<code>
<from:form action="showDetails" modelAttribute="employee">
Name<form:input path="name"/>
<form:errors path="name" />
<br>
<br>
Surname<form:input path="surname"/>
<form:errors path="surname" />
<input type="submit">
</from:form>
</code>
<from:form action="showDetails" modelAttribute="employee">
Name<form:input path="name"/>
<form:errors path="name" />
<br>
<br>
Surname<form:input path="surname"/>
<form:errors path="surname" />
<input type="submit">
</from:form>
How can i configure it correctly?
New contributor
Tima Khamza is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.