2012-10-08 24 views
-2

我在Grails中使用和CustomDateEditor麻烦2.​​1.0Grails的2.1和和CustomDateEditor似乎并没有工作

我想要实现:

Date类现在呈现为08/10/2013 00:00:00 CEST但我想的格式更改为2013年8月10日(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 ..这是怎么回事?

我搜索了所有的东西,它似乎并不是我的代码是错误的,但仍然无法正常工作。

非常感谢您提供任何提示。

+0

嗯..不知道,为什么2 downvote ..是这个问题那么糟吗? –

回答

1

如果范围f以您自己的自定义格式呈现日期,使用g:formatDate标记不是更好吗? 喜欢的东西:

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

检查formatDate文档

+0

是的,这很容易,但我想使用脚手架模板,所以我不能更改AFAIK,除此之外,问题仍然存在 –

+0

你在文档中看到过吗 _formatName(可选) - 从默认值查找格式使用此密钥的MessageSource/ResourceBundle(i18n/*。properties文件)。如果format和formatName为空,则使用'default.date.format'键查找格式。默认为'yyyy-MM-dd HH:mm:ss z'如果密钥没有指定_我从来没有使用它,但是你可以尝试把这个属性放在配置文件中,这样你就不用再改变了比属性:)希望它的作品 – rascio

+0

对于我所知道的(我记得)财产编辑是做其他的东西... – rascio

相关问题