How can I change the way GRAILS GSP fieldValue formats Integers?

前端 未结 8 1669
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-16 06:09

I have a field in my domain object which I define as an Integer...

Integer minPrice

I then access it in a GSP page as follows:



        
8条回答
  •  生来不讨喜
    2020-12-16 06:42

    Better use custom PropertyEditor in order not to bother with formatNumber tag every time you output a value. Like, declare a bean in resources.groovy:

    myOwnCustomEditorRegistrar(CustomEditorRegistrar)
    

    And create your class:

    class CustomEditorRegistrar implements PropertyEditorRegistrar {
        void registerCustomEditors(PropertyEditorRegistry registry) {
            registry.registerCustomEditor(BigDecimal.class, new MyBigDecimalEditor(BigDecimal.class))
        }
    }
    

提交回复
热议问题