List of usage examples for com.vaadin.data.validator StringLengthValidator StringLengthValidator
public StringLengthValidator(String errorMessage, Integer minLength, Integer maxLength)
From source file:org.jpos.qi.minigl.NewEntryForm.java
License:Open Source License
private void createAndBindFields(Binder binder) { TextField accountCode = createTextField("accountCode"); ComboBox layer = createLayersSelector(); TextField detail = createTextField("detail"); TextField tags = createTextField("tags"); TextField amount = createTextField("amount"); RadioButtonGroup credit = createCreditOrDebit(); binder.forField(accountCode).withNullRepresentation("").withConverter(new AccountConverter()) .withValidator((Validator<Account>) (value, context) -> { if (value != null && !(value instanceof FinalAccount)) return ValidationResult.error(app.getMessage("errorMessage.accountNotFinal")); else if (value == null) return ValidationResult.error(app.getMessage("errorMessage.req", StringUtils.capitalize(accountCode.getCaption()))); return ValidationResult.ok(); }).asRequired(app.getMessage("errorMessage.req", StringUtils.capitalize(layer.getCaption()))) .bind("account"); binder.forField(layer).withConverter(new ShortToLayerConverter(journal)) .asRequired(app.getMessage("errorMessage.req", StringUtils.capitalize(layer.getCaption()))) .bind("layer"); binder.forField(detail)//from ww w . j a va2s .co m .withValidator(new StringLengthValidator( app.getMessage("errorMessage.invalidField", detail.getCaption()), 0, 255)) .withValidator(new RegexpValidator(app.getMessage("errorMessage.invalidField", detail.getCaption()), TEXT_REGEX)) .bind("detail"); binder.forField(tags) .withValidator(new StringLengthValidator( app.getMessage("errorMessage.invalidField", tags.getCaption()), 0, 255)) .withValidator(new RegexpValidator(app.getMessage("errorMessage.invalidField", tags.getCaption()), TEXT_REGEX)) .withConverter(new StringToTagConverter()).bind("tags"); binder.forField(amount) .asRequired(app.getMessage("errorMessage.req", StringUtils.capitalize(amount.getCaption()))) .withConverter(new StringToBigDecimalConverter(app.getMessage("errorMessage.invalidAmount"))) .withValidator(new BigDecimalRangeValidator(app.getMessage("errorMessage.invalidAmount"), new BigDecimal("1"), new BigDecimal("99999999999999"))) .withNullRepresentation(BigDecimal.ZERO).bind("amount"); binder.bind(credit, "credit"); addComponent(accountCode); addComponent(layer); addComponent(detail); addComponent(tags); addComponent(amount); addComponent(credit); setComponentAlignment(credit, Alignment.BOTTOM_CENTER); }
From source file:org.jpos.qi.QIEntityView.java
License:Open Source License
protected List<Validator> getValidators(String propertyId) { List<Validator> validators = new ArrayList<>(); ViewConfig.FieldConfig config = viewConfig.getFields().get(propertyId); if (config != null) { String regex = config.getRegex(); int length = config.getLength(); String[] options = config.getOptions(); if (options != null) { //Change the field to a Combo loaded with the options ComboBox combo = new ComboBox(getCaptionFromId("field." + propertyId), Arrays.asList(options)); getBinder().bind(combo, propertyId); return null; }//from ww w .j ava 2 s. c o m if (regex != null) { validators.add( new RegexpValidator(getApp().getMessage("errorMessage.invalidField", propertyId), regex)); } if (length > 0) { validators.add(new StringLengthValidator( getApp().getMessage("errorMessage.invalidField", propertyId), 0, length)); } } return validators; }
From source file:org.jpos.util.FieldFactory.java
License:Open Source License
public List<Validator> getValidators(String propertyId) { if (viewConfig == null) return Collections.EMPTY_LIST; List<Validator> validators = new ArrayList<>(); ViewConfig.FieldConfig config = viewConfig.getFields().get(propertyId); if (config != null) { String regex = config.getRegex(); int length = config.getLength(); String[] options = config.getOptions(); if (options != null) { //Change the field to a Combo loaded with the options ComboBox combo = new ComboBox(getCaptionFromId("field." + propertyId), Arrays.asList(options)); getBinder().bind(combo, propertyId); return null; }/*from w ww . j a va 2 s . com*/ if (regex != null) validators.add( new RegexpValidator(getApp().getMessage("errorMessage.invalidField", propertyId), regex)); if (length > 0) validators.add(new StringLengthValidator( getApp().getMessage("errorMessage.invalidField", propertyId), 0, length)); } return validators; }