'null' value in form fields instead of blank

I implemented a Bean as:
public class SubscriptionBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String emailId;
private String confirmEmailId;

public String getConfirmEmailId() {
	return confirmEmailId;
}

public void setConfirmEmailId(String confirmEmailId) {
	this.confirmEmailId = confirmEmailId;
}

public String getEmailId() {
	return emailId;
}

public void setEmailId(String emailId) {
	this.emailId = emailId;
}

}

I generated a form based on it. When i see the form it comes up with ‘null’ in the emailId and confirmEmailId fields. So, how to get that blank?

TextField.setNullRepresentation(String nullRepresentation)

doing ((TextField)subscribeform.getField(“emailId”)).setNullRepresentation(“vik”);
has no effect. It still renders null in the emailId field.

Vik

Read this page (
http://vaadin.com/book/-/page/components.form.html
) about forms and FieldFactory. Use a FieldFactory and set the setNullRepresentation in it.


public Field createField(Item item, Object propertyId,
                             Component uiContext) {
    TexTfield text = new TextFiedl();
    text.setNullRepresentation("");
    return text;  
}

Btw. why the default null representation is ‘null’? I don’t see any reasonable scenario where text ‘null’ would be better option instead of ‘’ (empty string).

Even i agree that there is no reason to default it ‘null’ instead of blank.[quote=Antti Koski]

Btw. why the default null representation is ‘null’? I don’t see any reasonable scenario where text ‘null’ would be better option instead of ‘’ (empty string).
[/quote]

So this is the only way to get rid of the ‘null’ coming to it? in others words can’t get the text fields blank using item bean way of generating form?

The default is “null” for historical reasons. We wanted it to be symmetric to how System.out.println(“Value is” + null) would be.

No. You can use BeanItem just fine:

Form f = new Form();
f.setFormFieldFactory(new FormFieldFactory() {
    public Field createField(Item item, Object propertyId,
            Component uiContext) {
        Field field = DefaultFieldFactory.get().createField(item,
                propertyId, uiContext);
        if (field instanceof TextField) {
            ((TextField) field).setNullRepresentation("");
        }
        return field;
    }
});
f.setItemDataSource(new BeanItem(new Person()));

In practice this is not that much of extra as in most forms you want to set form field factory any case to customize the form behavior.