Hi, I'm using Struts 2, JPA and Spring 2 and I want to check if an e-mail address is already in use in my app, but I want to make it implementing a custom validator and so it may be solved as a fieldError.
My strategy is that in my UserEmailValidator I have an object of class UserBusiness as a attribute who says me if the e-mail is already in use or not, and Spring 2 injects the dependency for me. The problem is that my business attribute in UserEmailValidator class is coming with null value because Spring2 didn't make the injection of dependency. This is the code involving the problem: spring.xml - - - (...) <bean id="userBusiness" class="v1c2.business.impl.UserBusinessImpl" parent="crudBusiness" scope="singleton"> <property name="dao" ref="userDao" /> </bean> (...) <bean id="userEmailValidator" class="v1c2.validator.UserEmailValidator" scope="prototype"> <property name="business" ref="userBusiness" /> </bean> (...) - - - UserEmailValidator.java - - - package v1c2.validator; import v1c2.business.UserBusiness; import v1c2.pojo.User; import com.opensymphony.xwork2.validator.ValidationException; import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport; public class UserEmailValidator extends FieldValidatorSupport { private UserBusiness<User> business; public void validate(Object object) throws ValidationException { String email = (String) getFieldValue(getFieldName(), object); if (business.isEmailInUse(email)) { addFieldError(getFieldName(), object); } } public void setBusiness(UserBusiness<User> business) { this.business = business; } } - - - Is this the right strategy? I'm not too sure because Spring isn't making its work. How can I call a business' method in a FieldValidatorSupport extended class? Can anyone help me, please? []'s -- "Realize buscando o melhor, mas planeje esperando o pior." ______________________________ Alceu Medeiros http://www.inf.ufsc.br/~alceu