Spring Framework

Spring Projects

Spring Project 1

adplus-dvertising
Validate Interface in Spring MVC
Previous Home Next

The Validate Interface in Spring MVC provide the facility to give the service before execute of your action class and give the service after execute of your action class. This interface provide the following type of method which are:

supports:


boolean supports(Class clazz)

Can this Validator validate instances of the supplied clazz?

validate:

void validate(Object target,Errors errors)

Example

package mypack.validator;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;
import mypack.model.Registration;
import mypack.model.Registration;
@SuppressWarnings("unused")
public class RegistrationFormValidator 
implements Validator 
{
@SuppressWarnings("unchecked")
public boolean supports(Class clazz) {
return Registration.class.isAssignableFrom(clazz);
}
public void validate(Object obj, Errors errors) {
Registration registration = (Registration) obj;
ValidationUtils.rejectIfEmptyOrWhitespace(errors, 
"username", "error.blank.username");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, 
"password", "error.blank.password");
		
	}
}

Example of Validator Interface in Spring MVC

Previous Home Next