1 2 Previous Next 21 Replies Latest reply on Oct 15, 2007 3:31 AM by chawax Go to original post
      • 15. Re: How to write a validator that compares two fields
        chawax

        Sorry ... Please read "I added" and not "I had" ...

        • 16. Re: How to write a validator that compares two fields
          pmuir

          Must be META-INF/components.xml *on your classpath* i.e.

          WEB-INF/classes/META-INF/components.xml or WEB-INF/classes/seam.properties

          • 17. Re: How to write a validator that compares two fields
            chawax

            OK. It was working until now with components.xml in /WEB-INF, but I will follow your recommandation.

            I have a new problem with this validator since it is declared as a Seam component and no more in faces-config.xml. It looks like the ValidatorException is not caught !

            15:56:56,333 ERROR [ExceptionFilter] handling uncaught exception
            javax.servlet.ServletException
             at javax.faces.webapp.FacesServlet.service(FacesServlet.java:256)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
             at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:307)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
             at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
             at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
             at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
             at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:44)
             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
             at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
             at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
             at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
             at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
             at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:150)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
             at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
             at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
             at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
             at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
             at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
             at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
             at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
             at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
             at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
             at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
             at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
             at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
             at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
             at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
             at java.lang.Thread.run(Thread.java:595)
            Caused by: java.lang.reflect.InvocationTargetException
             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
             at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:585)
             at javassist.util.proxy.RuntimeSupport$DefaultMethodHandler.invoke(RuntimeSupport.java:37)
             at fr.horoquartz.t4.gui.validators.EqualsValidator_$$_javassist_5.validate(EqualsValidator_$$_javassist_5.java)
             at javax.faces.component.UIInput.validateValue(UIInput.java:1013)
             at javax.faces.component.UIInput.validate(UIInput.java:867)
             at javax.faces.component.UIInput.executeValidate(UIInput.java:1065)
             at javax.faces.component.UIInput.processValidators(UIInput.java:666)
             at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1030)
             at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1030)
             at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1030)
             at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1030)
             at org.richfaces.component.UISwitchablePanel.processValidators(UISwitchablePanel.java:219)
             at javax.faces.component.UIForm.processValidators(UIForm.java:229)
             at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1030)
             at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1030)
             at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:662)
             at org.ajax4jsf.component.AjaxViewRoot.access$201(AjaxViewRoot.java:59)
             at org.ajax4jsf.component.AjaxViewRoot$3.invokeRoot(AjaxViewRoot.java:321)
             at org.ajax4jsf.context.JsfOneOneInvoker.invokeOnRegionOrRoot(JsfOneOneInvoker.java:56)
             at org.ajax4jsf.context.AjaxContextImpl.invokeOnRegionOrRoot(AjaxContextImpl.java:173)
             at org.ajax4jsf.component.AjaxViewRoot.processValidators(AjaxViewRoot.java:335)
             at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:100)
             at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
             at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
             at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
             ... 40 more
            Caused by: javax.faces.validator.ValidatorException: Vous avez saisi deux mots de passe différents !
             at fr.horoquartz.t4.gui.validators.CompareValidator.validate(CompareValidator.java:35)
             at fr.horoquartz.t4.gui.validators.EqualsValidator_$$_javassist_5._d17validate(EqualsValidator_$$_javassist_5.java)
             ... 68 more
            


            EqualsValidator class is annotated with @Validator and it inherits CompareValidator which has the following validate() method :
            public void validate(FacesContext context, UIComponent cmp, Object value)
             throws ValidatorException {
             UIInput input = (UIInput) JSFUtils.findComponent(context.getViewRoot(), getCompareTo());
             if (! compare(value, input.getValue())) {
             String message = Messages.instance().get(getMessage());
             throw new ValidatorException(new FacesMessage(message));
             }
            }


            I had a look on the way ModelValidator or FormattedTextValidator are written in Seam sources and saw no difference in the way ValidatorException is thrown. Do you have any idea about this ?

            • 18. Re: How to write a validator that compares two fields
              pmuir

              Try using @BypassInterceptors

              • 19. Re: How to write a validator that compares two fields
                chawax

                Perfect !
                Thanks a lot.

                • 20. Re: How to write a validator that compares two fields
                  pmuir

                  It would be interesting to see if you can generalize this approach a bit to produce a validator that can work with two fields....


                  If you aren't interested in doing this, please open a jira issue - I've been wanting to look at something like this for a while.

                  • 21. Re: How to write a validator that compares two fields
                    chawax

                     

                    "pete.muir@jboss.org" wrote:
                    It would be interesting to see if you can generalize this approach a bit to produce a validator that can work with two fields....


                    Well, that's what my validator does : it compares the value of the field with the value of an other field. The name of this other field is given by the attribute "compareTo". Maybe the name of this attribute is not well choosed ?

                    I made similar validators for greaterThan, lessThan, greaterThanOrEquals, lessThanOrEquals, but I have not completely finished them.

                    I also think about supporting EL expressions in compareTo attribute, so that you can compare the value of the field with an attribute of a Seam component. But I don't really know how to do this ... Is there an example for this somewhere ?

                    When all will be finished, no problem for me to give the source code to the community ;)

                    1 2 Previous Next