Skip to content

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

@tircnf

Description

@tircnf

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions