Grails
  1. Grails
  2. GRAILS-2400

Command object w. 3 arguments custom validator, errors properties does not survive redirect

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0
    • Fix Version/s: 2.0 final
    • Component/s: None
    • Labels:
      None

      Description

      If my command object uses 3 arguments custom validator, errors properties does not survive redirect:

      e.g.

      class FooCommand {
        String bar 
      
        static constraints = {
          bar(
            nullable: true, 
            validator: { val, obj, errors ->
              if (SomeLogic.check(val, obj)) {
                errors.rejectValue('bar', 'errmsg', null, 'blah')
                return false
              }
              return true
            }
          )
        }
      }
      

      If my controller upon seeing command.hasErrors(), puts the command object somewhere, say in session, then redirect it to another controller/action, which retrieve the command object from the session, the errors properties does not report hasErrors().

      Incidentally, if I use the 2 args validator form, the errors dynamic properties is retained after a redirect.

        Activity

        Hide
        Mos added a comment -

        This is still an issue with Grails 1.3.6.

        From my point of view this is a problem with the dynamic 'errors' property. It isn't a real object reference but is resolved via Groovy magic. Therefore the errors object of a CommandObject or DomainObject isn't stored in the Web-Session.

        Workaround: Store the errors object in the session explicitly and reassign it if object is read

         
        def beforeRedirect = {
             ....
             session.cmd = cmd      
             session.cmd_errors = cmd.errors
             ....
        }   
        
        def afterRedirect = {
            ....
            def cmd = session.cmd
            cmd.errors = session.cmd_errors
            .....
        }
        
        Show
        Mos added a comment - This is still an issue with Grails 1.3.6. From my point of view this is a problem with the dynamic 'errors' property. It isn't a real object reference but is resolved via Groovy magic. Therefore the errors object of a CommandObject or DomainObject isn't stored in the Web-Session. Workaround: Store the errors object in the session explicitly and reassign it if object is read def beforeRedirect = { .... session.cmd = cmd session.cmd_errors = cmd.errors .... } def afterRedirect = { .... def cmd = session.cmd cmd.errors = session.cmd_errors ..... }
        Hide
        Mos added a comment -

        By the way: Shouldn't it be a Grails feature to automatically store the errors reference?

        Show
        Mos added a comment - By the way: Shouldn't it be a Grails feature to automatically store the errors reference?
        Hide
        Jeff Scott Brown added a comment -

        See the attached Grails 2.0.M1 project. I don't think this is a problem now that we have a real Errors property associated with validateable objects like command objects.

        Show
        Jeff Scott Brown added a comment - See the attached Grails 2.0.M1 project. I don't think this is a problem now that we have a real Errors property associated with validateable objects like command objects.

          People

          • Assignee:
            Burt Beckwith
            Reporter:
            Brian Guan
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development