Hi,
Is there a way I can enable some sort of auto-trim at the binder (i.e. when I do the binder.setField(xxx)) so that I won’t have to open up the bean later on and trim everything?? (names/addresses/etc etc).
Thanks!
Hi,
Is there a way I can enable some sort of auto-trim at the binder (i.e. when I do the binder.setField(xxx)) so that I won’t have to open up the bean later on and trim everything?? (names/addresses/etc etc).
Thanks!
No automatic feature that I know of, but it sounds like a useful feature. Maybe it could be doable with a Converter?
I guess I could use something like that
import com.vaadin.flow.data.binder.Result;
import com.vaadin.flow.data.binder.ValueContext;
import com.vaadin.flow.data.converter.Converter;
public class TrimmedStringConverter implements Converter<String, String>{
private static final long serialVersionUID = 1L;
private String errorMessage = "";
public TrimmedStringConverter(String errorMessage) {
this.errorMessage = errorMessage;
}
@Override
public Result<String> convertToModel(String value, ValueContext context) {
value = value.trim();
if(value.isEmpty())
return Result.error(errorMessage);
else
return Result.ok(value);
}
@Override
public String convertToPresentation(String value, ValueContext context) {
if(value == null)
return "";
else
return value.trim();
}
}
although it would be nice if I could use the ConverterFactory in order to put it straight into all the fields…