Issue
I use the following custom editor in MANY Spring-MVC controllers according to:
A controller
binder.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, NumberFormat.getNumberInstance(new Locale("pt", "BR"), true));
Other controller
binder.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, NumberFormat.getNumberInstance(new Locale("pt", "BR"), true));
Another controller
binder.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, NumberFormat.getNumberInstance(new Locale("pt", "BR"), true));
Notice the same custom editor registered
Question: how can i set up a global custom editor like this one in order to avoid set up each controller ?
regards,
Solution
You need to declare it in your application context:
<bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
<property name="customEditors"><map>
<entry key="java.math.BigDecimal">
<bean class="org.springframework.beans.propertyeditors.CustomNumberEditor">
... <!-- specify constructor-args here -->
</bean>
</entry>
</map></property>
</bean>
Details are here
Answered By - ChssPly76
Answer Checked By - Senaida (JavaFixing Volunteer)