格式化表格单元格中的值

时间:2015-09-09 08:42:12

标签: vaadin vaadin7

我制作了一张桌子和相应的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);

但我的环境仍然忽略了我,甚至没有错误消息!可能有什么问题?

1 个答案:

答案 0 :(得分:1)

我认为

Object v =  property.getValue();
当您使用SQLContainer时,

不返回Integer值,这就是您没有看到任何异常的原因,条件块没有被执行。

你能用断点检查吗?

相关问题