Olá pessoal estou fazendo alguns testes com o Spring MVC 3, seguindo o pdf da documentação, e não esta funcionando a validação:
//JSP
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="s" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page session="false" %>
<html>
<head>
<title>forms | mvc-showcase</title>
</head>
<body>
<form:form modelAttribute="user">
<form:errors path="*" cssClass="errorBox" />
<table>
<tr>
<td>First Name:</td>
<td><form:input path="firstName" /></td>
<td><form:errors path="firstName" /></td>
</tr>
<tr>
<td>Last Name:</td>
<td><form:input path="lastName" /></td>
<td><form:errors path="lastName" /></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="Save Changes" />
</td>
</tr>
</table>
</form:form>
</body>
</html>
//Classe de Validação
package br.com.pedrosa.validator;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;
import br.com.pedrosa.form.User;
public class UserValidator implements Validator {
public boolean supports(Class candidate) {
return User.class.isAssignableFrom(candidate);
}
public void validate(Object obj, Errors errors) {
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName","required", "Field is required.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName","required", "Field is required.");
}
}
//Chamada ao formulario
package br.com.pedrosa;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import br.com.pedrosa.form.User;
@Controller
public class OlaMundoController {
@RequestMapping("/ola")
public ModelAndView ola( @ModelAttribute("user") User user) {
String mensagem = "Conhecendo o Spring MVC 3.0";
ModelAndView modelAndView = new ModelAndView("user");
modelAndView.addObject("mensagem", mensagem);
return modelAndView;
}
}
O que mais preciso ajustar?