0

jQuery Datepicker を使用して人の生年月日を設定しようとしています。ただし、私が得るのはProperty dateOfBirth must be a valid Date.

したがって、もともと、私のコントローラーは次のようになります。

def update(Person personInstance) {
    if (personInstance == null) {
        // do Something
        return
    }

    if (personInstance.hasErrors()) {
        respond personInstance.errors, view: 'edit'
        return
    }

    // do the rest
}

jQuery ではSimpleDateFormat、適切なオブジェクトを生成するためにオブジェクトを使用する必要があることがわかりましたDate。それにもかかわらず、次のコード セグメントのように、新しいDateオブジェクトをドメイン オブジェクトに直接割り当ててdateOfBirth、その後ドメイン オブジェクトを検証しても、エラーが発生します。personInstanceProperty dateOfBirth must be a valid Date

def update(Person personInstance) {
    if (personInstance == null) {
        // do Something
        return
    }

    // added code
    personInstance.dateOfBirth = new Date()
    personInstance.validate()
    // added code

    if (personInstance.hasErrors()) {
        respond personInstance.errors, view: 'edit'
        return
    }

    // do the rest
}

助けてくれてありがとう:)

4

1 に答える 1