-
1. Re: Accessing Seam components from a custom JSF Validator?
t1mb0 Mar 23, 2008 3:02 PM (in response to t1mb0)I now feel a little daft as I've just spotted this in the docs (3.2.1)
Seam stateless session bean components may be instantiated usingComponent.getInstance()
or@In(create=true)
However I still wonder is it possible to have JSF resolve the above mentioned JSF validator as seam component
usernameValidator
without having to make it a hibernate validator? (hibernate seems to validate all the way to the database, but sometimes you just want validation on the front end only) -
2. Re: Accessing Seam components from a custom JSF Validator?
t1mb0 Mar 23, 2008 9:23 PM (in response to t1mb0)Now I'm seeing that the hibernate validator fails to validate whenever I add a custom JSF validator. If I comment out the JSF validator, then the hibernate validator will correct flag the field as invalid and the message is displayed.
Is there known issue issue where JSF validators effectively mask the hibernate validator? Can the two types of validator not co-exist?
I'm pulling my hair out with these validators so if anyone out there can explain this I'd be really grateful.
Thanks
Tim
-
3. Re: Accessing Seam components from a custom JSF Validator?
msystems Mar 24, 2008 12:16 AM (in response to t1mb0)I'm using JSF validators and Hibernate validators and it works fine for me - no problems.
BTW: have you tried:
@Name("usernameValidator") @Validator public class UsernameValidator implements javax.faces.validator.Validator { @In(create=true) AccountDao accountDao; public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { // validation logic } }
Remember to remove the configuration/declaration of the JSF validator from the faces-config.xml file.
-
4. Re: Accessing Seam components from a custom JSF Validator?
matt.drees Mar 24, 2008 2:24 AM (in response to t1mb0)IIRC, if you use s:validateAll, a model validator (Hibernate validator) will be attached only if another JSF validator isn't explicitly used. So, if you need both a model validator and another jsf validator, you should explicitly use s:validate.
-
5. Re: Accessing Seam components from a custom JSF Validator?
barbacena Mar 24, 2008 5:42 AM (in response to t1mb0)Hi Tim,
There is a Jira issue about this, then I don't recomend you using a @In on any validator or converter.
Use:
@Name("usernameValidator") @Validator @BypassInterceptors public class UsernameValidator implements javax.faces.validator.Validator { AccountDao accountDao = Component.getInstance("accountDao"); public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { // validation logic } }
IMHO, that's ugly, but that is the way they are going ... I think that is because they are trying to untie the seam and JSF.
-
6. Re: Accessing Seam components from a custom JSF Validator?
barbacena Mar 24, 2008 5:45 AM (in response to t1mb0)Hi Matt,
Isn't that a bug? IMHO, the behavior of s:validateAll should be the same of s:validate applied to every field.
-
7. Re: Accessing Seam components from a custom JSF Validator?
matt.drees Mar 25, 2008 7:25 AM (in response to t1mb0)No, it's definitely intentional. I forget exactly why, but I think it's discussed in previous forum posts.
However, this behavior isn't documented well in the reference docs (if at all; can't remember). It'd probably be worth a jira issue for that.
-
8. Re: Accessing Seam components from a custom JSF Validator?
t1mb0 Mar 25, 2008 10:36 PM (in response to t1mb0)Thanks to everyone who answered me on this.. All time and input is much appreciated!
In summary :-
I can confirm that using s:validate rather than s:validateAll does allow both JSF and hibernate validators to work together .. thanks for the tip Matt!
And pure JSF validators should not attempt to be Seam components themselves and should manually lookup or create a seam component if necessary.
This is my first seam application and already I can see its power as an integration framework. I will definitely be a frequenter of this site!
Thanks again,
Tim