1

As per the docs, we can use localized data binding. But this is not working in grails 4.

controller

import grails.databinding.BindingFormat

class TestController {

  def index() {
    render view: 'index'
  }

  def test(DateCommand command) {
    render "${params} <br/><br/> - ${command.errors?.collect { error -> error as String }?.join(', ')}"
  }
}

class DateCommand {

  @BindingFormat(code = 'date.field.format')
  Date aDate
  @BindingFormat('dd/MM/yyyy')
  Date bDate

  static constraints = {
    aDate(nullable: false)
    bDate(nullable: false)
  }
}

index view

<g:form action="test">
  <input type="text" name="aDate" value="27/04/2019" />
  <input type="text" name="bDate" value="27/04/2019" />
  <g:submitButton class="btn btn-success" name="OK" />
</g:form>

messages.properties

date.field.format=dd/MM/yyyy

Same code is working fine in grails 3.x.x

Am I missing some configuration or something is wrong in the code?

MKB
  • 7,587
  • 9
  • 45
  • 71

2 Answers2

2

Am I missing some configuration or something is wrong in the code?

It looks like the annotation handling may be broken for that. If you file an issue at https://github.com/grails/grails-core/issues we can get it straightened out.

Thanks for the feedback.

Jeff Scott Brown
  • 26,804
  • 2
  • 30
  • 47
0

Workaround --

command.aDate = params.date('aDate', message(code: 'date.field.format'))
command.clearErrors()
command.validate()

and implements CO with grails.validation.Validateable trait.

MKB
  • 7,587
  • 9
  • 45
  • 71