Reputation: 803
I have a Java web project with an html page and a controller class.
(there is a REST resources configuration class that sets resources path to /resources
but it is irrelevant to the question)
html page:
<html>
<head>
<title>Start Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<h1>Hello World!</h1>
<form action="resources/postman" method="POST">
<label for="ageInput">Age:</label>
<input type="number" id="ageInput" name="age"/><br/><br/>
<input type="submit" value="Submit"/>
</form>
</body>
</html>
and here is the controller class:
@Controller
@Path("postman")
public class PostController {
@MvcBinding
@FormParam("age")
@Min(18)
private int age;
@Inject
private BindingResult bindingResult;
@Inject
private Models models;
@POST
public String processForm() {
if (bindingResult.isFailed()) {
models.put("errors", bindingResult.getAllMessages());
return "fail.jsp";
}
return "success.jsp";
}
}
The problem is no matter what value I provide in the ageInput
validation is always successful. I can provide both negative values as well as positive lower than 18 and I always am redirected to success.jsp
.
What can I do to trigger the validation?
I am using Eclipse Krezo as an implementation of Jakarta MVC api.
Upvotes: 0
Views: 13