-2

Grails 2.1.0 で CustomDateEditor を使用できません

私が達成しようとしていること:

Date クラスは 08/10/2013 00:00:00 CEST としてレンダリングされるようになりましたが、形式を 08/10/2013 (dd/MM/yyyy 形式) に変更したい

私がこれまでに行ったこと:

resource.groovy

beans = {
    customPropertyEditorRegistrar(myutil.CustomPropertyEditorRegistrar)
}

myutil.CustomPropertyEditorRegistrar

package myutil

import org.springframework.beans.PropertyEditorRegistrar
import org.springframework.beans.PropertyEditorRegistry
import org.springframework.beans.propertyeditors.CustomDateEditor
import java.text.SimpleDateFormat

public class CustomPropertyEditorRegistrar implements PropertyEditorRegistrar {
    public void registerCustomEditors(PropertyEditorRegistry registry) {
        registry.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat('dd/MM/yyyy'), true)) //this doesn't work
        registry.registerCustomEditor(java.math.BigDecimal.class, new CurrencyPropertyEditor()) //this work so at least the registerCustomEditors method is invoked
    }
}

私のコードでわかるように、正常に動作する CurrencyPropertyEditor があるため、ここで混乱しています..何が起こっているのですか?

私はあちこち検索しましたが、私のコードが間違っているようには見えませんが、まだ機能していません。

ヒントをお寄せいただきありがとうございます。

4

1 に答える 1

1

これが独自のカスタム形式で日付をレンダリングするスコープの場合、g:formatDateタグを使用する方が良いのではないでしょうか? 何かのようなもの:

 <g:formatDate format="dd/MM/yyyy" date="${date}"/>

formatDateのドキュメントを確認してください

于 2012-10-08T15:31:29.530 に答える