Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Default capitalization for table cells in Vaadin 7.4?
Hi,
I wonder if someone could help me with the following issue.
After Vaadin was upgraded to 7.4.0 from 7.3.6, all values in table cells are capitalized. For instance the values Incomingpayment or Booked are shown instead of values like IncomingPayment or BOOKED.
The issue happens in the version 7.5.0, too.
It doesn't seem to be a CSS issue, as the values are already converted in HTML:
With the same data source the version 7.4 shows the following:
<div class="v-table-cell-wrapper" style="text-align: left; width: 249px;">Incomingpayment</div>
<div class="v-table-cell-wrapper" style="text-align: left; width: 257px;">Booked</div>
As the version 7.3.6:
<div class="v-table-cell-wrapper" style="text-align: left; width: 251px;">IncomingPayment</div>
<div class="v-table-cell-wrapper" style="text-align: left; width: 256px;">BOOKED</div>
Java code is something like:
final com.vaadin.ui.Table paymentsTable = new com.vaadin.ui.Table();
paymentsTable.setContainerDataSource(new com.vaadin.data.util.BeanItemContainer<>(Payment.class, payments));
Thanks in advance,
Ferenc
Hi,
I found the faulty class: StringToEnumConverter
It was added to 7.4 with the commit https://github.com/vaadin/vaadin/commit/34934d1055d2451a3633d4380648ce661da17ce7
I think this kind of behavioural change should have been made optional and parameterized.
Regards,
Ferenc
Hi,
If anyone else is annoyed by the the above issue, here you are the solution:
A custom StringToEnumConverter:
public class CustomStringToEnumConverter extends com.vaadin.data.util.converter.StringToEnumConverter {
private static final long serialVersionUID = 1L;
@Override
public String convertToPresentation(final Enum value, final Class<? extends String> targetType, final Locale locale)
throws ConversionException {
if (value == null) {
return null;
}
return value.toString();
}
private <T extends Enum<T>> T stringToEnum(final String value, final Class<T> enumType) throws ConversionException {
try {
final EnumSet<T> set = EnumSet.allOf(enumType);
for (final T e : set) {
if (e.toString().equals(value)) {
return e;
}
}
}
catch (final Exception e) {
// Ignore
}
return null;
}
@SuppressWarnings("unchecked")
@Override
public Enum convertToModel(final String value, @SuppressWarnings("rawtypes") final Class<? extends Enum> targetType,
final Locale locale) throws ConversionException {
if (value == null)
return null;
return stringToEnum(value, targetType);
}
}
Use it in a custom converter factory:
public class CustomConverterFactory extends com.vaadin.data.util.converter.DefaultConverterFactory {
private static final long serialVersionUID = 1L;
@Override
protected Converter<String, ?> createStringConverter(final Class<?> sourceType) {
if (Enum.class.isAssignableFrom(sourceType)) {
return new CustomStringToEnumConverter();
}
return super.createStringConverter(sourceType);
}
}
And register the factory in the your Vaadin application:
VaadinSession.getCurrent().setConverterFactory(new CustomConverterFactory());
Regards,
Ferenc