List of usage examples for com.google.gwt.validation.client.impl Validation buildDefaultValidatorFactory
public static ValidatorFactory buildDefaultValidatorFactory()
ValidatorFactory instance based on the default Bean Validation provider. From source file:com.gafactory.core.client.ui.editors.BaseEditorPresenter.java
License:Open Source License
@Override public void validate() { final T dto = getView().getDriver().flush(); Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); Set<ConstraintViolation<T>> violations = doValidate(dto, validator); if (!violations.isEmpty()) { getView().handleViolations(violations); }//from w ww . ja v a 2 s . c o m }
From source file:com.gafactory.core.client.ui.editors.BaseEditorPresenter.java
License:Open Source License
@Override public void onSave(final boolean close) { getView().setSaveButtonEnabled(false); final T dto = getView().getDriver().flush(); Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); Set<ConstraintViolation<T>> violations = doValidate(dto, validator); if (!violations.isEmpty()) { /*for (ConstraintViolation<T> violation : violations) { getEventBus().fireEvent(new ShowAlertEvent(violation.getPropertyPath() + " " +violation.getMessage(), AlertType.DANGER)); /*from ww w . j a va2 s . c o m*/ }*/ getView().handleViolations(violations); } else { RestAction<SavingResult<ID>> action; action = service.save(dto); AlertingNotifingAsyncCallback<SavingResult<ID>> callback = new AlertingNotifingAsyncCallback<SavingResult<ID>>( getEventBus()) { @Override public void success(SavingResult<ID> result) { if (result.isSaved()) { if (close) { onBack(); } else { onSaved(); load(result.getId()); } } else { getEventBus().fireEvent(new ShowAlertEvent( messages.validationFailed(result.getErrorMessage()), AlertType.WARNING)); getView().setSaveButtonEnabled(true); } } @Override public void failure(Throwable caught) { super.failure(caught); getView().setSaveButtonEnabled(true); } }; dispatcher.execute(action, callback); callback.checkLoading(); } }
From source file:com.pronoiahealth.olhie.client.features.dialogs.EventCalendarRequestDialog.java
License:Open Source License
/** * Check for form errors//w w w . j a v a 2 s . c o m * * @return */ private boolean hasSubmissionErrors() { Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); // proxy needs to be unwrapped to work with the validator CalendarRequest cr = getUnwrappedModelData(); Set<ConstraintViolation<CalendarRequest>> violations = validator.validate(cr); for (ConstraintViolation<CalendarRequest> cv : violations) { String prop = cv.getPropertyPath().toString(); if (prop.equals("title")) { titleErrors.setText(cv.getMessage()); titleGroup.setType(ControlGroupType.ERROR); } else if (prop.equals("description")) { eventDescriptionErrors.setText(cv.getMessage()); eventDescriptionGroup.setType(ControlGroupType.ERROR); } else if (prop.equals("contactEmail")) { contactEmailErrors.setText(cv.getMessage()); contactEmailGroup.setType(ControlGroupType.ERROR); } } // Return value if (violations.isEmpty()) { return false; } else { return true; } }
From source file:com.pronoiahealth.olhie.client.features.dialogs.NewBookDialog.java
License:Open Source License
/** * Validates the form and sets errors when needed * /*from ww w. j a v a 2 s .c o m*/ * @return * @throws DataValidationException */ public Book validateForm() throws DataValidationException { clearErrors(); Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); // proxy needs to be unwrapped to work with the validator Book book = getUnwrappedModelData(); Set<ConstraintViolation<Book>> violations = validator.validate(book); // Check the easy stuff boolean foundError = false; for (ConstraintViolation<Book> cv : violations) { String prop = cv.getPropertyPath().toString(); if (prop.equals("bookTitle")) { bookTitleCG.setType(ControlGroupType.ERROR); foundError = true; } else if (prop.equals("introduction")) { introductionCG.setType(ControlGroupType.ERROR); foundError = true; } else if (prop.equals("keywords")) { keywordsCG.setType(ControlGroupType.ERROR); foundError = true; } } // Check the category and book drop down String cat = catagoryDropDown.getText().trim(); if (cat.trim().equals("Select a category")) { categoryCG.setType(ControlGroupType.ERROR); foundError = true; } else { book.setCategory(cat); } String cov = bookCoverDropDown.getText().trim(); if (cov.trim().equals("Select a book cover")) { bookCoverCG.setType(ControlGroupType.ERROR); foundError = true; } else { book.setCoverName(cov); } if (foundError == false) { return book; } else { throw new DataValidationException(); } }
From source file:com.pronoiahealth.olhie.client.features.dialogs.RegisterForm.java
License:Open Source License
/** * @return/* w w w . j ava 2s .c o m*/ * @throws DataValidationException */ public RegistrationForm validateForm() throws DataValidationException { clearErrors(); Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); // proxy needs to be unwrapped to work with the validator RegistrationForm rf = getUnwrappedModelData(); Set<ConstraintViolation<RegistrationForm>> violations = validator.validate(rf); boolean foundErr = false; for (ConstraintViolation<RegistrationForm> cv : violations) { String prop = cv.getPropertyPath().toString(); if (prop.equals("lastName")) { lastNameErr.setText(cv.getMessage()); foundErr = true; } else if (prop.equals("firstName")) { firstNameErr.setText(cv.getMessage()); foundErr = true; } else if (prop.equals("email")) { emailErr.setText(cv.getMessage()); foundErr = true; } else if (prop.equals("userId")) { userIdErr.setText(cv.getMessage()); foundErr = true; } else if (prop.equals("pwd")) { pwdErr.setText(cv.getMessage()); foundErr = true; } else if (prop.equals("organization")) { organizationErr.setText(cv.getMessage()); foundErr = true; } } Boolean authorBVal = author.getValue(); if (authorBVal == null) { author.setValue(Boolean.FALSE); } if (!pwd.getValue().equals(pwdRepeat.getValue())) { pwdRepeatErr.setText("Passwords must match. Please retype."); foundErr = true; } // User must accept the policy statement if this is a new registration if ((acceptedPolicyStatement.getValue() == null || acceptedPolicyStatement.getValue().booleanValue() == false) && mode == RegistrationEventEnum.NEW) { acceptedPolicyStatementErr.setText("You must accept the policy statement."); foundErr = true; } // If any errors throw and exception // else return the form data if (foundErr == true) { throw new DataValidationException("Found error(s)."); } else { return rf; } }
From source file:com.pronoiahealth.olhie.client.features.dialogs.ResetPwdDialog.java
License:Open Source License
/** * Check that the password matches the regEx and that the re-entered * password is the same as the passowrd/*www . j a v a 2 s .c om*/ * * @return true if there are errors */ private boolean hasSubmissionErrors() { boolean ret = false; // This may be over kill but at least its consistent with the // registration form process Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); Set<ConstraintViolation<RegistrationForm>> violations = validator.validateValue(RegistrationForm.class, "pwd", password.getText(), Default.class); // Check the password for match against the password regEx (defined on // the RegistrationForm value object) for (ConstraintViolation<RegistrationForm> cv : violations) { String prop = cv.getPropertyPath().toString(); if (prop.equals("pwd")) { passwordErrors.setText(cv.getMessage()); passwordGroup.setType(ControlGroupType.ERROR); ret = true; } } // The password and the re typed password must match if (!password.getValue().equals(reEnterPassword.getValue())) { reEnterPasswordErrors.setText("Passwords must match. Please retype."); reEnterPasswordGroup.setType(ControlGroupType.ERROR); ret = true; } // Return value after validation return ret; }