Search code examples
vaadinvaadin7

Formatting the value in the cell of a table


I made a table and the corresponding SQLContainer. The table have a column with phone numbers. In db table type of the corresponding column is a int. I wish formatting values of Vaadin table, in such way that view phone numbers become without comas or dots like separator of thousand(8,888 -> 8888).

I have already made similar thing to the Table which data source is a JPAContainer on this way:

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);
            }
        };

And everything works well. But when i made similar construction with SQLContiner instead of JPAContainer formatting is simply ignored. Affter that i try to change the way like this:

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);

But still my environment ignores me, even no error messages! What can be problem?


Solution

  • I think

    Object v =  property.getValue();
    

    is not returning an Integer value when you use the SQLContainer and that's why you are not seeing any exceptions, the conditional block is not being executed.

    Can you check that with a break point?