Change Textfield to PasswordField in autogenerated form.

hello , i am newbie to vaadin , i use autogenerated form from bean , in that there is a field called password which is shown as textfield by default , is there anyway to set secret to it . Thanx in advance

Use FieldFactory

class MyFieldFactory extends  DefaultFieldFactory {
    public Field createField(Item item, Object propertyId,
                             Component uiContext) {
        String pid = (String) propertyId;
        if ("password".equals(pid)) {
            TextField textField = new TextField("Password");
            textField.setSecret(true);
            return textField;
        }
        return super.createField(item, propertyId, uiContext); 
    }
}
...
form.setFieldFactory(new MyFieldFactory());

Starting from 6.5, TextField#setSecret is
deprecated
, so the new correct solution is:


class MyFieldFactory extends  DefaultFieldFactory {
    public Field createField(Item item, Object propertyId,
                             Component uiContext) {
        String pid = (String) propertyId;
        if ("password".equals(pid)) {
            AbstractTextField textField = new PasswordField("Password");
            return textField;
        }
        return super.createField(item, propertyId, uiContext);
    }
}
...
form.setFieldFactory(new MyFieldFactory());