Setting null value representation when using BeanFieldGroup

When using this code the form renders properly but the default value in the field is null. How can I customize these values?

final BeanFieldGroup binder = new BeanFieldGroup(Account.class);

	binder.setItemDataSource(account);
	binder.bindMemberFields(account);
	
	
	layout.addComponent(binder.buildAndBind("Account Name", "accountName"));
	layout.addComponent(binder.buildAndBind("User Name", "userName"));
	layout.addComponent(binder.buildAndBind("Password", "password"));
	//layout.addComponent(binder.buildAndBind("Address", "streetAddress"));
	layout.addComponent(binder.buildAndBind("City", "city"));
	layout.addComponent(binder.buildAndBind("State", "state"));
	layout.addComponent(binder.buildAndBind("Zip", "zip"));
	layout.addComponent(binder.buildAndBind("Email", "email"));
	layout.addComponent(binder.buildAndBind("Website", "website"));

Thanks in advance.

Yep, that is nasty bad default in Vaadin. The official solution is to call setNullRepresentation(“”) for each and every textfield you have. My solution is to use
Viritin
and its MTextField that has this bad default fixed.

BTW. I’d suggest to create fields for each property in your form and then use naming based binding “BeanFieldGroup.bindFieldsUnbuffered(account, this);”. This will make it much more easier to customize your form.

cheers,
matti

Hi Eric, you can customize the component returned by buildAndBind as you prefer - although you have to downcast manually from Field<?> to access eg. TextField.setNullRepresentation. As Matti said, you might prefer to create member fields for your components.

However, you can also ensure that all the text fields created by your FieldGroup have customization by setting a field factory, eg:

binder.setFieldFactory(new DefaultFieldGroupFieldFactory() {
    @Override
    protected <T extends AbstractTextField> T createAbstractTextField(
            Class<T> fieldType) {
        T field = super.createAbstractTextField(fieldType);
        field.setNullRepresentation("");
        return field;
     }
});

Thanks guys.
I just went back to the most fundamental way of adding fields to a layout with out using the beanFieldGroup.
While this implentation is more tedious, it makes the code more readable in my opinion.