package com.vst.webapp.validators;
import com.vst.model.Gost;
import com.vst.service.GostManager;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
/**
* Created by IntelliJ IDEA.
* User: And Lilia
* Date: 15.04.2009
* Time: 16:42:37
* To change this template use File | Settings | File Templates.
*/
public class GostValidator implements Validator {
GostManager gostManager;
public void setGostManager(GostManager gostManager) {
this.gostManager = gostManager;
}
public boolean supports(Class aClass) {
return Gost.class.isAssignableFrom(aClass);
}
public void validate(Object o, Errors errors) {
Gost gost=(Gost)o;
if (gost==null || gost.getGostName().trim().equals("") || gost.getGostAbout().trim().equals("")){
if (gost==null || gost.getGostAbout().trim().equals("")) {
errors.rejectValue("gostAbout","insert.gostAbouterror");
}
if (gost==null || gost.getGostName().trim().equals("") ){
errors.rejectValue("gostName", "gost.nullerror");
}
}else
{
if (gostManager.isGostExist(gost) && gost.getGostId()==null){
errors.rejectValue("gostName", "gost.existerror");
}
}
}
}