Hi.
I’m trying to use some masked fields in my forms, and Vaadin don’t have them. I just downloaded the add on MaskedTextField and I’m having some problems the project runs normally but don’t display anything the code is here:
import com.example.testefinal.util.ExampleUtil;
import com.vaadin.data.Item;
import com.vaadin.data.validator.IntegerValidator;
import com.vaadin.data.validator.StringLengthValidator;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.DefaultFieldFactory;
import com.vaadin.ui.Field;
import com.vaadin.ui.MaskedTextField;
import com.vaadin.ui.PasswordField;
import com.vaadin.ui.TextField;
@SuppressWarnings("serial")
public class PessoaFieldFactory extends DefaultFieldFactory {
final ComboBox countries = new ComboBox("País");
private static final String COMMON_FIELD_WIDTH = "12em";
public PessoaFieldFactory() {
countries.setWidth("100%");
countries.setContainerDataSource(ExampleUtil.getISO3166Container());
countries.setItemCaptionPropertyId(ExampleUtil.iso3166_PROPERTY_NAME);
countries.setItemIconPropertyId(ExampleUtil.iso3166_PROPERTY_FLAG);
countries.setFilteringMode(ComboBox.FILTERINGMODE_STARTSWITH);
}
@Override
public Field createField(Item item, Object propertyId, Component uiContext) {
Field f;
if ("countryCode".equals(propertyId)) {
// filtering ComboBox w/ country names
return countries;
} else if ("password".equals(propertyId)) {
// Create a password field so the password is not shown
f = createPasswordField(propertyId);
} else if ("cpf".equals(propertyId)) {
// Create a masked field
f = createMaskedTextField(propertyId);
} else {
// Use the super class to create a suitable field base on the
// property type.
f = super.createField(item, propertyId, uiContext);
}
if ("nome".equals(propertyId)) {
TextField tf = (TextField) f;
tf.setRequired(true);
tf.setRequiredError("Favor inserir um nome");
tf.setWidth(COMMON_FIELD_WIDTH);
tf.addValidator(new StringLengthValidator(
"Nome deve conter de 3-25 caracteres", 3, 25, false));
} else if ("sobrenome".equals(propertyId)) {
TextField tf = (TextField) f;
tf.setRequired(true);
tf.setRequiredError("Favor inserir um sobrenome");
tf.setWidth(COMMON_FIELD_WIDTH);
tf.addValidator(new StringLengthValidator(
"Nome deve conter de 3-50 caracteres", 3, 50, false));
} else if ("password".equals(propertyId)) {
PasswordField pf = (PasswordField) f;
pf.setRequired(true);
pf.setRequiredError("Favor inserir uma senha");
pf.setWidth("10em");
pf.addValidator(new StringLengthValidator(
"Senha deve conter de 6-20 caracteres", 6, 20, false));
} else if ("cpf".equals(propertyId)) {
MaskedTextField mf = (MaskedTextField) f;
mf = new MaskedTextField(mf.getCaption(), "###.###.###-##");
//mf.setNullRepresentation("");
//mf.setNullSettingAllowed(true);
mf.addValidator(new IntegerValidator("CPF deve conter apenas caracteres numéricos"));
//mf.setWidth("10em");
}
return f;
}
private PasswordField createPasswordField(Object propertyId) {
PasswordField pf = new PasswordField();
pf.setCaption(DefaultFieldFactory.createCaptionByPropertyId(propertyId));
return pf;
}
private MaskedTextField createMaskedTextField(Object propertyId) {
MaskedTextField mf = new MaskedTextField();
mf.setCaption(DefaultFieldFactory.createCaptionByPropertyId(propertyId));
return mf;
}
}
But when I use without the mask it works.
Someone knows what is going on there or have a better solution for masked fields?