Announcement Announcement Module
Collapse
No announcement yet.
Validator with HttpServletRequest access Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Validator with HttpServletRequest access

    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:

    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");
    }
    }
    Unfortunately this is currently not possible because validate has only access to Object and Errors. Any ideas how to circumvent this limitation?

  • #2
    One solution could be to override the onBindAndValidate method in the form itself. This would get the job done, but it would split your validation over more than on object which is a shame.

    Hope this helps

    Comment


    • #3
      Hmm, that sound like either i am missing something or this should be a feature request !?

      Comment

      Working...
      X