本文整理汇总了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.");
}
}
}