Validateable 'defaultNullable' not working when CommandObject is defined inside a Controller class if the command object class does not explicitly implement Validateable. #10091

Closed
tircnf opened this Issue Aug 6, 2016 · 3 comments

Projects

None yet

3 participants

@tircnf
tircnf commented Aug 6, 2016 edited

When a CommandObject is added directly to a Controller.groovy file, and the CommandObject is not marked with 'implements Validateable'

overriding defaultNullable() does not work.

Steps to Reproduce

  1. Create a grails app.
  2. Generate a controller.
  3. Create a command Object in the Controller file with 'static boolean defaultNullable() {true}', relying on the fact that Command Objects are Validateable by default in controllers, and do not manually add the "implements Validateable" clause.
  4. Create a controller action that expects the command Object as a parameter.
  5. Call that controller action without any arguments.
  6. Examine the command object.

Expected Behaviour

The CommandObject should validate and not have any errors.

According to section 8.1.9 of the manual

If the command object is defined in the same source file as the controller that is using it, Grails will automatically make it Validateable. It is not required that command object classes be validateable.

Validate is being called, but the validate method is not respecting the defaultNullable() override.

Actual Behaviour

The CommandObject has a validation error for every property.

Environment Information

  • Operating System: Windows
  • Grails Version: 3.1.9
  • JDK Version: 1.7_80
  • Container Version (If Applicable): grails run-app

Example Application

This example application exposes one controller with two actions.
https://github.com/tircnf/grails-command-object

http://localhost:8080/command/command1
and
http://localhost:8080/command/command2

command1 uses a patientCommand object that does not 'implement Validateable' and throws validation errors.
command2 uses a command object that does implement it.

Both command objects try to override the static defaultNullable method.

@jeffbrown jeffbrown changed the title from Validateable 'defaultNullable' not working when CommandObject is defined inside a Controller class. to Validateable 'defaultNullable' not working when CommandObject is defined inside a Controller class if the command object class does not explicitly implement Validateable. Aug 7, 2016
@jameskleeh jameskleeh self-assigned this Aug 13, 2016
@jameskleeh
Contributor
jameskleeh commented Aug 22, 2016 edited

I created a branch where this is done except for an issue I encountered. https://github.com/grails/grails-core/tree/GRAILS-10091. The issue is documented in a failing tests in grails-plugin-controllers

@jameskleeh jameskleeh added this to the grails-3.2.1 milestone Sep 17, 2016
@graemerocher graemerocher removed their assignment Oct 6, 2016
@graemerocher
Member

@jameskleeh anything I can do to help move this forward so the fix can be applied?

@jameskleeh
Contributor

@graemerocher If you could take a look at it, that would be great. I'm stumped. Check out the branch and run the tests to see the failing test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment