我做了一个表和相应的SQLContainer。表格的一列中包含电话号码。在db表中,对应列的类型为int。我希望格式化Vaadin表的值,以使查看电话号码时没有逗号或点,例如千位分隔符(8,888-> 8888)。
我已经通过这种方式对Table做了类似的事情,该表的数据源是JPAContainer:
Table imenikTable = new Table("Imenik", imenikData){
/**
*
*/
private static final long serialVersionUID = 8213291207581835298L;
@Override
protected String formatPropertyValue(Object rowId,
Object colId, @SuppressWarnings("rawtypes") Property property) {
Object v = property.getValue();
if (v instanceof Integer) {
DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance(getLocale());
df.applyLocalizedPattern("##00");
return df.format(v);
}
return super.formatPropertyValue(rowId, colId, property);
}
};
而且一切正常。但是,当我使用SQLContiner而不是JPAContainer进行类似的构造时,格式设置将被忽略。之后,我尝试更改这种方式:
StringToIntegerConverter plainIntegerConverter = new StringToIntegerConverter(){
private static final long serialVersionUID = -7517984934588222147L;
protected NumberFormat getFormat(Locale locale){
NumberFormat format = super.getFormat(locale);
format.setGroupingUsed(false);
return format;
}
};
contaktListTable.setConverter("telbr", plainIntegerConverter);
但是,我的环境仍然忽略了我,甚至没有错误消息!可能是什么问题?
我想
Object v = property.getValue();
使用SQLContainer时未返回Integer值,这就是为什么看不到任何异常,条件块未执行的原因。
您可以检查断点吗?
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句