The simplest approach is to replace characters in the datatype. Below is an example of converting commas to dots for English locale, so it doesn’t matter if the user enters a dot or a comma, both will be used as a decimal separator.
Create a datatype:
package com.company.demo;
import com.haulmont.chile.core.datatypes.impl.BigDecimalDatatype;
import org.dom4j.Element;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.Locale;
public class MyBigDecimalDatatype extends BigDecimalDatatype {
public MyBigDecimalDatatype(Element element) {
super(element);
}
@Override
public BigDecimal parse(String value, Locale locale) throws ParseException {
if (value != null) {
value = value.replace(',', '.');
}
return super.parse(value, locale);
}
}
Register it in metadata.xml with the same parameters as the original datatype in CUBA (keep format and separators as is because here they are used only for conversion without locale, so they are not relevant):
Hi Konstantin i have a similar problem but now if i use the dot of numpad it remain dot…i want comma instead…i have tried your example but i have too many bigdecimal datatype configured on my project…Is there another method to change the dot in comma?..i have read about overriding the bigdecimal dataype…how i can do it?
Regards
thank you konstantin…no i’m on cuba 7…Do you mean that the solution that the February 2020 solution replaces the “.” without changing the datatype of the entity fields? I noticed that for some fields (with datatype bigdecimal) it works well, for others (equally bigdecimal) it works randomly… could it be a cache problem?
First make sure you are on the latest CUBA 7.2.20. If the problem persists, try to find differences between the fields where it works and where it doesn’t. Set a breakpoint to your MyBigDecimalDatatype code and debug it.