Spring自定义编辑器

时间:2013-07-08 08:25:51

标签: java spring spring-mvc property-editor

我已经为spring处理程序添加了自定义属性编辑器。它适用于jspx页面上的一个属性,但不适用于其他属性,因为它只输出to Money of Money类。

public void initBinder(final HttpServletRequest request, final ServletRequestDataBinder binder) {
    binder.registerCustomEditor(Money.class, new MoneyPropertyEditor());
}

在带有Money类型的jspx属性中引用为:

<cat:input type="text" uiid="amount" bindpath="form.pack.amount"/>€

Money属性编辑器看起来像

public String getAsText() {
        String textValue = null;

        if (this.getValue() != null) {
            Money money = (Money) this.getValue();

            System.out.println("getAsText money: " + money);

            textValue = String.valueOf(money.getAmount());

            System.out.println("textValue: " + textValue);
        }

        return textValue;
    }

系统输出是:

getAsText money: Money:  Amount: 0.7, AsCents: 70
textValue: 0.7

所以 - 属性编辑器工作并被调用。但输入仍然适用于字符串表示:money: Money: Amount: 0.7, AsCents: 70而不是0.7

还应该配置什么以便使用输出自定义属性编辑器?

1 个答案:

答案 0 :(得分:0)

问题解决了!实际上,在这种情况下,PropertyEditor工作正常,后来由外部js修改了字段。