Добрый день, Роман.
Спасибо за ответ.
Сделал Datatype:
package com.ekom.ekomerp;
import com.google.common.base.Strings;
import com.haulmont.chile.core.annotations.JavaClass;
import com.haulmont.chile.core.datatypes.Datatype;
import javax.annotation.Nullable;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.Locale;
@JavaClass(BigDecimal.class)
public class PercentageDatatype implements Datatype<BigDecimal> {
private static final String PATTERN = "###,###.####%";
@Override
public String format(@Nullable Object value) {
if (value == null)
return "";
DecimalFormat format = new DecimalFormat(PATTERN);
return format.format(value);
}
@Override
public String format(@Nullable Object value, Locale locale) {
return format(value);
}
@Nullable
@Override
public BigDecimal parse(@Nullable String value) throws ParseException {
if (Strings.isNullOrEmpty(value))
return null;
DecimalFormat format = new DecimalFormat(PATTERN);
BigDecimal taxRate = BigDecimal.valueOf(format.parse(value).doubleValue());
return taxRate;
}
@Nullable
@Override
public BigDecimal parse(@Nullable String value, Locale locale) throws ParseException {
return parse(value);
}
}
Зарегистрировал в metadata.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<metadata xmlns="http://schemas.haulmont.com/cuba/metadata.xsd">
<datatypes>
<datatype id="fourDigitsScaleBigDecimal"
class="com.ekom.ekomerp.FourDigitsScaleBigDecimal"
decimalSeparator="."
format="#0.0000"
groupingSeparator=""/>
<datatype id="twoDigitsScaleBigDecimal"
class="com.ekom.ekomerp.TwoDigitsScaleBigDecimal"
decimalSeparator="."
format="#0.00"
groupingSeparator=""/>
<datatype id="fourDigitsScaleDouble"
class="com.ekom.ekomerp.FourDigitsScaleDouble"
decimalSeparator="."
format="#0.0000"
groupingSeparator=""/>
<datatype id="percent" class="com.ekom.ekomerp.PercentageDatatype"/>
</datatypes>
<metadata-model namespace="ekomerp"
root-package="com.ekom.ekomerp">
<class>com.ekom.ekomerp.entity.SpecificationTreeNode</class>
<class>com.ekom.ekomerp.entity.WeekTaskEntry</class>
</metadata-model>
</metadata>
Создал генерируемую колонку:
@Inject
private PercentageDatatype percentageDatatype;
public void init(Map<String, Object> params) {
purchaseOrderLineTable.addGeneratedColumn("taxRate",entity -> {
TextField textField = (TextField) factory.createComponent(TextField.NAME);
textField.setEditable(true);
textField.setDatasource(purchaseOrderLineTable.getItemDatasource(entity), "taxRate");
textField.setDatatype(percentageDatatype);
return textField;
});
}
Форматирование не применяется. В чем может быть проблема?