本文整理匯總了Java中org.springframework.validation.ValidationUtils類的典型用法代碼示例。如果您正苦於以下問題:Java ValidationUtils類的具體用法?Java ValidationUtils怎麽用?Java ValidationUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ValidationUtils類屬於org.springframework.validation包,在下文中一共展示了ValidationUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: validate
import org.springframework.validation.ValidationUtils; //導入依賴的package包/類
public void validate(Object target, Errors errors) {
CustomerInfo custInfo = (CustomerInfo) target;
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "fName", "NotEmpty.customerForm.fName");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lName", "NotEmpty.customerForm.lName");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "NotEmpty.customerForm.email");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "address", "NotEmpty.customerForm.address");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "phone", "NotEmpty.customerForm.phone");
if(!errors.hasErrors() && custInfo.getPhone().length()!=10){
errors.rejectValue("phone","Length.greater.phone");
}
if(!errors.hasErrors() && custInfo.getPhone().contains("[0-9]+")){
errors.rejectValue("phone","NoCharacater.cusomerForm.phone");
}
if (!errors.hasErrors() && !emailValidator.isValid(custInfo.getEmail())) {
errors.rejectValue("email", "NotValid.customer.email");
}
}
示例2: validate
import org.springframework.validation.ValidationUtils; //導入依賴的package包/類
/**
* Validates the input
* @param object the user to validate
* @param errors the errors
*/
public void validate(Object object, Errors errors) {
ServiceDTO user = (ServiceDTO) object;
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "field.required",
"Service name must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "description", "field.required",
"Service description must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "isActive", "field.required",
"Service isActive must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "wide", "field.required",
"Service wide must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "tall", "field.required",
"Service tall must not be empty.");
}
示例3: validate
import org.springframework.validation.ValidationUtils; //導入依賴的package包/類
@Override
public void validate(Object target, Errors errors) {
System.out.println("validate(Object target, Errors errors) ");
System.out.println(target);
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userId",
"required.userName", "Field name is required.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password",
"required.password", "Field name is required.");
System.out.println("validate() : - "+errors);
Logon logon = (Logon)target;
if(logon.getPassword()!=null && !(logon.getPassword().equals(logon.getUserId()+"111"))){
errors.rejectValue("password", "invalid.logon");
System.out.println("rejected");
}
}
示例4: validate
import org.springframework.validation.ValidationUtils; //導入依賴的package包/類
@Override
public void validate(Object obj, Errors errors) {
// TODO Auto-generated method stub
Book book = (Book) obj;
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "bookName", "bookName.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "author", "authorName.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "description", "description.required");
if (book.getDescription().length() < 10 || book.getDescription().length() > 40) {
errors.rejectValue("description", "description.length",
"Please enter description within 40 charaters only");
}
if (book.getISBN() <= 150l) {
errors.rejectValue("ISBN", "ISBN.required", "Please Enter Correct ISBN number");
}
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "price", "price.incorrect");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "publication", "publication.required");
}
示例5: validate
import org.springframework.validation.ValidationUtils; //導入依賴的package包/類
@Override
public void validate(Object target, Errors errors) {
System.out.println("Entered : validate(Object target, Errors errors) ");
System.out.println("target : " + target);
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userId",
"required.userName", "Field name is required.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password",
"required.password", "Field name is required.");
Logon logon = (Logon) target;
if("blank".equals(logon.getUserRole())){
errors.rejectValue("userRole", "required.role");
}
if(logon.getDaysCount()==null){
errors.rejectValue("daysCount", "required.dayscount");
}
if (logon.getPassword() != null
&& !(logon.getPassword().equals(logon.getUserId() + "111"))) {
errors.rejectValue("password", "invalid.logon");
}
System.out.println("validate() : - " + errors);
}
示例6: validate
import org.springframework.validation.ValidationUtils; //導入依賴的package包/類
@Override
public void validate(Object o, Errors errors) {
UserEntity user = (UserEntity) o;
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "NotEmpty");
if (user.getName().length() < 3 || user.getName().length() > 32) {
errors.rejectValue("username", "Size.userForm.username");
}
if (userRepository.findByName(user.getName(), firstPageSingleItemRequest).hasContent()) {
errors.rejectValue("username", "Duplicate.userForm.username");
}
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "NotEmpty");
if (user.getPassword().length() < 3) {
errors.rejectValue("password", "Size.userForm.password");
}
}
示例7: validate
import org.springframework.validation.ValidationUtils; //導入依賴的package包/類
@Override
public void validate(Object target, Errors errors) {
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "field.required");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "field.required");
User user = (User) target;
passwordValidator.validate(user.getRawPassword(), errors);
}
示例8: validate
import org.springframework.validation.ValidationUtils; //導入依賴的package包/類
@Override
public void validate(Object target, Errors errors) {
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "employeeFirstName", "NotEmpty.registration.fname");
Employee employeeRegistration = (Employee) target;
if (StringUtils.isNotBlank(employeeRegistration.getEmpPassword())) {
if (passwordValidator.validate(employeeRegistration.getEmpPassword())) {
//Check if the confirmation password is same as the new password.
if (!StringUtils.equalsIgnoreCase(employeeRegistration.getEmpPassword(), employeeRegistration.getEmpPassword2())) {
errors.rejectValue("empPassword2", "NotValid.registration.confirm.password");
}
} else {
errors.rejectValue("empPassword", "NotValid.registration.password");
}
}
}
示例9: SiteOptionMapDtoValidationTests
import org.springframework.validation.ValidationUtils; //導入依賴的package包/類
@Test
public void SiteOptionMapDtoValidationTests() {
SiteOptionMapDTO siteOptionMapDTO = SiteOptionMapDTO.withGeneralSettings(
null,
siteOptions.getSiteDescription(),
siteOptions.getAddGoogleAnalytics(),
siteOptions.getGoogleAnalyticsTrackingId(),
siteOptions.getUserRegistration())
.build();
Errors errors = new BeanPropertyBindingResult(siteOptionMapDTO, "siteOptionMapDTO");
ValidationUtils.invokeValidator(new SiteOptionMapDtoValidator(), siteOptionMapDTO, errors);
assertTrue(errors.hasFieldErrors("siteName"));
assertEquals("EMPTY", errors.getFieldError("siteName").getCode());
}
示例10: validate
import org.springframework.validation.ValidationUtils; //導入依賴的package包/類
@Override
public void validate(Object object, Errors errors) {
WeatherLocationDTO weatherLocationDTO = (WeatherLocationDTO) object;
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userId", "field.required",
"User Id must not be empty");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "city", "field.required",
"City must not be empty");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "state", "field.required",
"State must not be empty");
if(!errors.hasErrors()) {
if(weatherLocationDTO.getState().length() != 2) {
errors.rejectValue("state", "filed.invalid",
"State must be length 2. Did you forget to use state code?");
}
}
}
示例11: validate
import org.springframework.validation.ValidationUtils; //導入依賴的package包/類
@Override
public void validate(Object o, Errors errors) {
TodoListDTO todoListDTO = (TodoListDTO) o;
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userId", "field.required",
"User Id must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "field.required",
"Name must not be empty.");
}
示例12: validate
import org.springframework.validation.ValidationUtils; //導入依賴的package包/類
@Override
public void validate(Object o, Errors errors) {
UpdateTaskDTO updateTaskDTO = (UpdateTaskDTO) o;
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "taskId", "field.required",
"User Id must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "description", "field.required", "" +
"Description must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "dueDate", "field.required",
"Due Date must not be empty");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "isCompleted", "field.required",
"Is Completed must not be empty");
}
示例13: validate
import org.springframework.validation.ValidationUtils; //導入依賴的package包/類
/**
* Validates the input
* @param object the user to validate
* @param errors the errors
*/
public void validate(Object object, Errors errors) {
UpdateServiceDTO user = (UpdateServiceDTO) object;
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "field.required",
"Service name must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "description", "field.required",
"Service description must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "isActive", "field.required",
"Service isActive must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "wide", "field.required",
"Service wide must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "tall", "field.required",
"Service tall must not be empty.");
}
示例14: validate
import org.springframework.validation.ValidationUtils; //導入依賴的package包/類
/**
* Validates the input
* @param object the user to validate
* @param errors the errors
*/
public void validate(Object object, Errors errors) {
UserDTO user = (UserDTO) object;
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "googleId", "field.required",
"googleId must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "fullName", "field.required",
"User Full Name must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "givenName", "field.required",
"User Given Name must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "familyName", "field.required",
"User Family Name must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "imageURL", "field.required",
"User Image URL must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "field.required",
"User Email must not be empty");
ValidationUtils.rejectIfEmpty(errors, "role", "field.required",
"User Role must not be empty.");
// doing specific input validaiton, so we need to make sure all of the fields are there
if(!errors.hasErrors()) {
if(user.getRole() < 0 || user.getRole() > 1) {
errors.rejectValue("role", "field.invalid", "User Role must be 0 or 1");
}
if(!EmailValidator.getInstance().isValid(user.getEmail())) {
errors.rejectValue("email", "field.invalid", "User Email must be a valid email address.");
}
if(!UrlValidator.getInstance().isValid(user.getImageURL())) {
errors.rejectValue("imageURL", "field.invalid", "User Image URl must be a valid web address.");
}
}
}
示例15: validate
import org.springframework.validation.ValidationUtils; //導入依賴的package包/類
@Override
public void validate(Object o, Errors errors) {
UpdateUserDTO user = (UpdateUserDTO) o;
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userId", "field.required",
"User Id must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "googleId", "field.required",
"googleId must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "fullName", "field.required",
"User Full Name must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "givenName", "field.required",
"User Given Name must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "familyName", "field.required",
"User Family Name must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "imageURL", "field.required",
"User Image URL must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "field.required",
"User Email must not be empty");
ValidationUtils.rejectIfEmpty(errors, "role", "field.required",
"User Role must not be empty.");
// doing specific input validaiton, so we need to make sure all of the fields are there
if(!errors.hasErrors()) {
if(user.getRole() < 0 || user.getRole() > 1) {
errors.rejectValue("role", "field.invalid", "User Role must be 0 or 1");
}
if(!EmailValidator.getInstance().isValid(user.getEmail())) {
errors.rejectValue("email", "field.invalid", "User Email must be a valid email address.");
}
if(!UrlValidator.getInstance().isValid(user.getImageURL())) {
errors.rejectValue("imageURL", "field.invalid", "User Image URl must be a valid web address.");
}
}
}