Vaadin Table doesn't respect Application locale

Hello,

It seems to me that Vaadin Table doesn’t use Application locale to show objects.

For example,


Table t = new Table("My Table");
t.addContainerProperty("date", java.util.Date.class, null);
...

Locale has no effect how date shows in the table. Any ideas how this should be done?

I tried putting localized dates to Labels using ColumnGenerator but then Table had problems deciding correct column width.

Table doesn’t know anything about Date:s, it just uses toString() to show the value for any object that isn’t a Component.

In order to make Labels in a generated column use proper amount of space, do setSizeUndefined() for them.

OK, that seems to work.

Still I think it should support localizing basic java types using java.text.DateFormat.getDateTimeInstance for dates and NumberFormat for numbers.

I solved this by creating my own ‘CustomTable’ subclass overrides a method as below:


    /**
     * Formats table cell property values. By default the property.toString()
     * and return a empty string for null properties.
     * 
     * @param rowId
     *            the Id of the row (same as item Id).
     * @param colId
     *            the Id of the column.
     * @param property
     *            the Property to be formatted.
     * @return the String representation of property and its value.
     * @since 3.1
     */
	@Override
    protected String formatPropertyValue(Object rowId, Object colId,
            Property property) {
        if (property == null) {
            return "";
        }
        
        if(property.getType().equals(java.util.Date.class)){
        	return getDateFormatter().format((java.util.Date)property.getValue());
        }
        
        return property.toString();
    }	
	
	private FastDateFormat getDateFormatter(){
		if(dateFormatter != null){
			return dateFormatter;
		}
		
		Locale locale = getParent().getApplication().getLocale();
		dateFormatter = FastDateFormat.getInstance("EEE d MMM yy", locale);
		
		return dateFormatter;
	}

Just make dateFormatter an instance field in your own Table subclass. You should use your own format string.

Now, I’m sorting out how to deal with timezone info. Thinking of just making a GMT offset, and asking users to enter this info.