I am asking myself how I could use the validator facility to do more complex tasks than simply checking fields for value ranges and such. To do that i'd need access to the HttpServletRequest to implement validation routines like these:
Unfortunately this is currently not possible because validate has only access to Object and Errors. Any ideas how to circumvent this limitation?Code:public void validate(Object obj, Errors errors, HttpServletRequest request) { Certificate certificate = (Certificate) obj; User user = (User) request.getSession().getAttribute("user"); if (!certificate.getUser().getId().equals(user.getId())) { // User is trying to access an object he does not own errors.rejectValue("certificate", "error.wrong.user.access", null, "Illegal user access"); } }


Reply With Quote