Vaadin 7: Grid using Renderer instead Converter

I recently discovered a 2nd way to give format to data, instead of a Converter use a Renderer but this second does not seem to work.

this works:

.getColumn(3).setConverter(new StringToDateConverter() {
            @Override
            protected DateFormat getFormat(Locale locale) {
                return new SimpleDateFormat("HH:mm");
            }
        });

this doesn’t: it showing in the cell the String “HH:mm” instead the Date formatted

getColumn(3).setRenderer(new DateRenderer("HH:mm"));

What am I doing wrong?

PD: forum bug > the button to format “code” in the topic doesn’t work

Hi,
as stated in
DateRenderer javadocs
the string you pass to the constructor is a “format string” as defined in

http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#syntax
, not a date format pattern.

In your case you can use
%tR
as format string (see
http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#dt
)

getColumn(3).setRenderer(new DateRenderer("%tR")); HTH
Marco

Hi,

If you want to keep using date format patterns instead of “format strings” as indicated by Marco, the only thing you need to do is passing a SimpleDateFormat object to your DateRender constructor.

String sPattern = "HH:mm";

getColumn(3).setRenderer(new DateRenderer(new SimpleDateFormat(sPattern)));

Hope it helps

Miguel