如果我有一个带有BigDecimal
属性的对象,则要Table
以一种特定的格式显示它:2个小数,并根据数量显示一个“ +”或“-”符号。
例如:+10.50
,-3.20
如何在vaadin表中实现这一目标?有一种方法table.setConverter(..)
,但这实际上将迫使在aBigDecimal.class
和a之间进行转换String.class
。我需要的只是一个视图格式化程序,它以不同的方式显示对象数据。
Override
受保护的方法Table.formatPropertValue()
:
public class My_table
extends Table
{
@Override
protected String formatPropertyValue(final Object a_row_id,
final Object a_col_id,
final Property<?> a_property)
{
if (a_property.getType() == BigDecimal.class
&& null != a_property.getValue())
{
return "formatted-value";
}
return super.formatPropertyValue(a_row_id, a_col_id, a_property);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句