本文整理汇总了Java中org.springframework.validation.Errors类的典型用法代码示例。如果您正苦于以下问题:Java Errors类的具体用法?Java Errors怎么用?Java Errors使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Errors类属于org.springframework.validation包,在下文中一共展示了Errors类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validate
import org.springframework.validation.Errors; //导入依赖的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.Errors; //导入依赖的package包/类
@Override
public void validate(Object target, Errors errors) {
String password = null;
if (target instanceof PasswordChangeRequest) {
password = ((PasswordChangeRequest) target).getPassword();
} else if (target instanceof String) {
password = target.toString();
}
if (password != null && password.length() < MINIMUM_PASSWORD_LENGTH) {
errors.rejectValue("password", "field.min.length", new Object[]{MINIMUM_PASSWORD_LENGTH},
"The password must be at least [" + MINIMUM_PASSWORD_LENGTH + "] characters in length.");
}
}
示例3: validate
import org.springframework.validation.Errors; //导入依赖的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.Errors; //导入依赖的package包/类
@Override
public void validate(Object o, Errors errors) {
Evento evento = (Evento) o;
if(evento.getNombre().equalsIgnoreCase("")){
errors.rejectValue("nombre" , "error.evento", "Campo vacio. Rellenalo");
}
else if(evento.getLugar().equalsIgnoreCase("")){
errors.rejectValue("lugar" , "error.evento", "Campo vacio. Rellenalo");
}
else if (evento.getDescripcion().equalsIgnoreCase("")) {
errors.rejectValue("descrpcion" , "error.evento", "Campo vacio. Rellenalo");
}
else if(evento.getFechaInicio().after(evento.getFechaFin())) {
errors.rejectValue("fechaInicio" , "error.evento", "Fecha posterior a la de Fin. Ajustela");
}
}
示例5: validate
import org.springframework.validation.Errors; //导入依赖的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: register
import org.springframework.validation.Errors; //导入依赖的package包/类
@RequestMapping(value = "/register", method = RequestMethod.POST)
public String register(@ModelAttribute @Valid RegisterForm form, Errors errors, HttpServletRequest request) {
if (errors.hasErrors()) {
return "register";
}
User existingUser = userDao.findByUsername(form.getUsername());
if (existingUser != null) {
errors.rejectValue("username", "username.alreadyexists", "A user with that username already exists");
return "register";
}
User newUser = new User(form.getUsername(), form.getPassword());
userDao.save(newUser);
setUserInSession(request.getSession(), newUser);
return "redirect:";
}
示例7: login
import org.springframework.validation.Errors; //导入依赖的package包/类
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String login(@ModelAttribute @Valid LoginForm form, Errors errors, HttpServletRequest request) {
if (errors.hasErrors()) {
return "login";
}
User theUser = userDao.findByUsername(form.getUsername());
String password = form.getPassword();
if (theUser == null) {
errors.rejectValue("username", "user.invalid", "The given username does not exist");
return "login";
}
if (!theUser.isMatchingPassword(password)) {
errors.rejectValue("password", "password.invalid", "Invalid password");
return "login";
}
setUserInSession(request.getSession(), theUser);
return "redirect:";
}
示例8: validate
import org.springframework.validation.Errors; //导入依赖的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");
}
}
示例9: validate
import org.springframework.validation.Errors; //导入依赖的package包/类
/**
* validates the data
* @param object the household to validate
* @param errors the errors
*/
public void validate(Object object, Errors errors) {
ServiceAndHouseholdDTO serviceAndHouseholdDTO = (ServiceAndHouseholdDTO) object;
if(serviceAndHouseholdDTO.getServiceId() == null) {
errors.rejectValue("serviceId", "field.required", "Service ID must not be empty.");
}
if(serviceAndHouseholdDTO.getHouseholdId() == null) {
errors.rejectValue("householdId", "field.required", "Household ID must not be empty.");
}
// ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userId", "field.required",
// "User ID must not be empty.");
//
// ValidationUtils.rejectIfEmptyOrWhitespace(errors, "householdId", "field.required",
// "Household ID must not be empty.");
}
示例10: validatePasswords
import org.springframework.validation.Errors; //导入依赖的package包/类
/**
* Validate passwords input
* <ul>
* <li>password is not empty</li>
* <li>password has appropriate length</li>
* <li>password and repeated password match</li>
* </ul>
* @param password to validate
* @param repeatedPassword to validate
* @param errors resulting to validation
*/
public void validatePasswords(String password, String repeatedPassword, Errors errors) {
String cleanPassword = StringUtils.trimToEmpty(password);
if (StringUtils.isBlank(cleanPassword)) {
errors.rejectValue("password", "validation.error.password.blank");
} else if (StringUtils.length(cleanPassword) < config.getPasswordLength()) {
errors.rejectValue("password", "validation.error.password.tooShort", new Object[]{config.getPasswordLength()}, StringUtils.EMPTY);
} else {
String cleanRepeatedPassword = StringUtils.trimToEmpty(repeatedPassword);
if (!StringUtils.equals(cleanPassword, cleanRepeatedPassword)) {
errors.rejectValue("repeatedPassword", "validation.error.password.noMatch");
}
}
}
示例11: validate
import org.springframework.validation.Errors; //导入依赖的package包/类
/**
* validates the data
* @param object the household to validate
* @param errors the errors
*/
public void validate(Object object, Errors errors) {
UserAndHouseholdDTO userAndHouseholdDTO = (UserAndHouseholdDTO) object;
if(userAndHouseholdDTO.getUserId() == null) {
errors.rejectValue("userId", "field.required", "User ID must not be empty.");
}
if(userAndHouseholdDTO.getHouseholdId() == null) {
errors.rejectValue("householdId", "field.required", "Household ID must not be empty.");
}
// ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userId", "field.required",
// "User ID must not be empty.");
//
// ValidationUtils.rejectIfEmptyOrWhitespace(errors, "householdId", "field.required",
// "Household ID must not be empty.");
}
示例12: validate
import org.springframework.validation.Errors; //导入依赖的package包/类
@Override
public void validate(Object obj, Errors errors) {
Pet pet = (Pet) obj;
String name = pet.getName();
// name validation
if (!StringUtils.hasLength(name)) {
errors.rejectValue("name", REQUIRED, REQUIRED);
}
// type validation
if (pet.isNew() && pet.getType() == null) {
errors.rejectValue("type", REQUIRED, REQUIRED);
}
// birth date validation
if (pet.getBirthDate() == null) {
errors.rejectValue("birthDate", REQUIRED, REQUIRED);
}
}
示例13: validateClientId
import org.springframework.validation.Errors; //导入依赖的package包/类
private void validateClientId(ClientDetailsFormDto clientDetailsDto, Errors errors) {
final String clientId = clientDetailsDto.getClientId();
if (StringUtils.isEmpty(clientId)) {
errors.rejectValue("clientId", null, "client_id is required");
return;
}
if (clientId.length() < 5) {
errors.rejectValue("clientId", null, "client_id 长度至少5位");
return;
}
boolean existed = oauthService.isExistedClientId(clientId);
if (existed) {
errors.rejectValue("clientId", null, "client_id [" + clientId + "] 已存在");
}
}
示例14: updateHousehold
import org.springframework.validation.Errors; //导入依赖的package包/类
/**
* Updates the househole information
* @param updateHouseholdDTO the user information to update
* @param errors an error container
* @return the udpated user
*/
@RequestMapping(method = RequestMethod.PUT, value = "/", produces = "application/json")
public ResponseEntity updateHousehold(@RequestBody UpdateHouseholdDTO updateHouseholdDTO, Errors errors) {
UpdateHouseholdValidator houseValidator = new UpdateHouseholdValidator();
houseValidator.validate(updateHouseholdDTO, errors);
ValidationError validationError = ValidationErrorBuilder.fromBindErrors(errors);
if(errors.hasErrors()) {
throw new IllegalRequestFormatException("Could not update household.", "/household", validationError);
}
Household updatedHousehold= this.householdService.updateHousehold(updateHouseholdDTO);
return ResponseEntity.ok(updatedHousehold);
}
示例15: valideerDatumLigtNaDatum
import org.springframework.validation.Errors; //导入依赖的package包/类
/**
* Valideer dat een datum (tweedeDatum) na een andere datum (eersteDatum) ligt. Indien een van de datums niet gevuld
* is, wordt de validatie niet uitgevoerd.
* @param errors errors object
* @param eersteDatum eerste datum
* @param tweedeDatum tweede datum (die na de eerste datum moet liggen)
* @param veldEersteDatum veld code (voor errors object)
* @param veldTweedeDatum veld code (voor errors object)
*/
public static void valideerDatumLigtNaDatum(
final Errors errors,
final Integer eersteDatum,
final Integer tweedeDatum,
final String veldEersteDatum,
final String veldTweedeDatum) {
if (eersteDatum != null && tweedeDatum != null) {
LOG.info(VALIDEER_DATUM_LIGT_NA_DATUM_EERSTE_DATUM_TWEEDE_DATUM, tweedeDatum, eersteDatum);
valideer(
errors,
vulOnbekendeDelenEindDatumAan(tweedeDatum) > eersteDatum,
veldTweedeDatum,
VELD_MOETLATERZIJN,
veldEersteDatum,
veldTweedeDatum);
}
}