List of usage examples for com.vaadin.data ValidationResult ok
public static ValidationResult ok()
From source file:org.jpos.qi.eeuser.UsersHelper.java
License:Open Source License
public Validator getNickTakenValidator() { return (Validator<String>) (value, context) -> { String oldNick = getOriginalEntity() != null ? ((User) getOriginalEntity()).getNick() : null; if (oldNick != null) { User u = getUserByNick((String) value, true); if (u == null || u.getId().equals(((User) getOriginalEntity()).getId())) { return ValidationResult.ok(); }//from w ww . java2 s . c om return ValidationResult.error(getApp().getMessage("errorMessage.nickAlreadyExists", value)); } else { if (getUserByNick((String) value, true) == null) { return ValidationResult.ok(); } return ValidationResult.error(getApp().getMessage("errorMessage.nickAlreadyExists", value)); } }; }
From source file:org.jpos.qi.eeuser.UsersHelper.java
License:Open Source License
public Validator getPasswordsMatchValidator(final PasswordField newPass) { return (Validator<String>) (value, context) -> { if (!newPass.getValue().equals(value)) return ValidationResult.error(getApp().getMessage("error.passwordsMatch")); return ValidationResult.ok(); };/*from ww w . j av a 2 s .co m*/ }
From source file:org.jpos.qi.eeuser.UsersHelper.java
License:Open Source License
public Validator getCurrentPasswordMatchValidator() { return (Validator<String>) (value, context) -> { try {// w w w . jav a 2 s . co m boolean passwordOk = (boolean) DB.exec((db) -> { UserManager mgr = new UserManager(db); try { return mgr.checkPassword((User) getOriginalEntity(), (String) value); } catch (BLException e) { return false; } }); return passwordOk ? ValidationResult.ok() : ValidationResult.error(getApp().getMessage("error.invalidPassword")); } catch (Exception e) { getApp().getLog().error(e); return ValidationResult.error(e.getMessage()); } }; }
From source file:org.jpos.qi.eeuser.UsersHelper.java
License:Open Source License
public Validator getNewPasswordNotUsedValidator() { return (Validator<String>) (value, context) -> { if (getOriginalEntity() != null) { try { boolean ok = (boolean) DB.exec((db) -> { db.session().refresh(getOriginalEntity()); UserManager mgr = new UserManager(db); try { return mgr.checkNewPassword((User) getOriginalEntity(), (String) value); } catch (BLException e) { return false; }// w w w . ja v a2s. c o m }); return ok ? ValidationResult.ok() : ValidationResult.error(getApp().getMessage("error.passwordUsed")); } catch (Exception e) { getApp().getLog().error(e); } } return ValidationResult.ok(); }; }
From source file:org.jpos.qi.minigl.AccountsView.java
License:Open Source License
@Override protected List<Validator> getValidators(String propertyId) { List<Validator> validators = super.getValidators(propertyId); if ("currencyCode".equalsIgnoreCase(propertyId)) { Validator<String> currencyCodeValidator = (Validator<String>) (value, context) -> { Account parentAccount = getInstance().getParent(); if (parentAccount != null && parentAccount.getCurrencyCode() != null && !parentAccount.getCurrencyCode().equals(value)) { return ValidationResult.error(getApp().getMessage("errorMessage.currencyCodeMismatch")); }/*from www . j a v a 2s . c om*/ return ValidationResult.ok(); }; validators.add(currencyCodeValidator); } return validators; }
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 v a 2 s .c o 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); }