5 Replies Latest reply on Jul 28, 2011 2:54 AM by hantsy bai

    FacesValitator error in Seam 3 and TOMCAT

    hantsy bai Master

      I created a seam3 web project, and added some seam3 mouldes in pom.xml.
      And I copied the CurrentPasswordValidator from Seam Booking example to my application, but when I entered to the page, I got an exception.




      An Error Occurred:
      
      Expression Error: Named Object: currentPasswordValidator not found.
      - Stack Trace
      
      javax.faces.FacesException: Expression Error: Named Object: currentPasswordValidator not found.
           at com.sun.faces.application.ApplicationImpl.createValidator(ApplicationImpl.java:1564)
           at org.jboss.weld.environment.servlet.jsf.ForwardingApplication.createValidator(ForwardingApplication.java:174)
           at org.jboss.seam.faces.environment.SeamApplicationWrapper.createValidator(SeamApplicationWrapper.java:67)
           at org.jboss.seam.faces.environment.org$jboss$weld$bean-flat-ManagedBean-class_org$jboss$seam$faces$environment$SeamApplicationWrapper_$$_WeldClientProxy.createValidator(org$jboss$weld$bean-flat-ManagedBean-class_org$jboss$seam$faces$environment$SeamApplicationWrapper_$$_WeldClientProxy.java)
           at com.sun.faces.facelets.tag.jsf.ValidatorTagHandlerDelegateImpl.createValidator(ValidatorTagHandlerDelegateImpl.java:238)
           at com.sun.faces.facelets.tag.jsf.ValidatorTagHandlerDelegateImpl.applyAttachedObject(ValidatorTagHandlerDelegateImpl.java:132)
           at com.sun.faces.facelets.tag.jsf.ValidatorTagHandlerDelegateImpl.applyNested(ValidatorTagHandlerDelegateImpl.java:205)
           at com.sun.faces.facelets.tag.jsf.ValidatorTagHandlerDelegateImpl.apply(ValidatorTagHandlerDelegateImpl.java:87)
           at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
           at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
           at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:184)
           at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
           at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
           at com.sun.faces.facelets.tag.jsf.CompositeComponentTagHandler.applyNextHandler(CompositeComponentTagHandler.java:187)
           at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:184)
           at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
           at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
           at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
           at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:184)
           at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
           at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
           at com.sun.faces.facelets.tag.ui.DefineHandler.applyDefinition(DefineHandler.java:103)
           at com.sun.faces.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:178)
           at com.sun.faces.facelets.impl.DefaultFaceletContext$TemplateManager.apply(DefaultFaceletContext.java:395)
           at com.sun.faces.facelets.impl.DefaultFaceletContext.includeDefinition(DefaultFaceletContext.java:366)
           at com.sun.faces.facelets.tag.ui.InsertHandler.apply(InsertHandler.java:108)
           at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
           at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
           at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:184)
           at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
           at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
           at com.sun.faces.facelets.tag.jsf.core.ViewHandler.apply(ViewHandler.java:164)
           at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
           at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
           at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
           at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:86)
           at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:308)
           at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:367)
           at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:346)
           at com.sun.faces.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:199)
           at com.sun.faces.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:155)
           at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
           at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:86)
           at com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:152)
           at com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:769)
           at org.jboss.seam.faces.view.SeamViewDeclarationLanguage.buildView(SeamViewDeclarationLanguage.java:81)
           at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:100)
           at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
           at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.jboss.seam.servlet.event.ServletEventBridgeFilter.doFilter(ServletEventBridgeFilter.java:72)
           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.exception.CatchExceptionFilter.doFilter(CatchExceptionFilter.java:65)
           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:233)
           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
           at java.lang.Thread.run(Thread.java:662)



      Related code:



      @FacesValidator("currentPasswordValidator")
      public class CurrentPasswordValidator implements Validator {
      
          @Inject
          private BundleTemplateMessage messageBuilder;
          @Inject
          @Authenticated
          private User currentUser;
          @Inject
          Messages messages;
      
          public void validate(final FacesContext ctx, final UIComponent comp,
                  final Object value) throws ValidatorException {
              String currentPassword = (String) value;
              if ((currentUser.getPassword() != null)
                      && !currentUser.getPassword().equals(currentPassword)) {
      
                  throw new ValidatorException(new FacesMessage(messageBuilder.key(new DefaultBundleKey("account_passwordsDoNotMatch")).defaults("Passwords do not match").build().getText()));
              }
          }
      }
      



      change password page.




      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
           xmlns:ui="http://java.sun.com/jsf/facelets"
           xmlns:f="http://java.sun.com/jsf/core"
           xmlns:h="http://java.sun.com/jsf/html"
           xmlns:s="http://jboss.org/seam/faces"
           xmlns:p="http://http://java.sun.com/jsf/composite/components/property"
           template="/WEB-INF/templates/default.xhtml">
      
           <ui:define name="content">
      
                <div class="section">
                <h1>Change Your Password</h1>
                </div>
      
                <div class="section">
      
                <div class="errors"><h:messages id="messages" globalOnly="true" />
                </div>
      
                <h:form id="pwdForm" prependId="false">
      
                     <fieldset><p:input id="current" label="Current password">
                          <h:inputSecret id="input" value="#{currentUser.password}">
                               <f:validator validatorId="currentPasswordValidator" />
                          </h:inputSecret>
                     </p:input> <p:input id="new" label="New password">
                          <h:inputSecret id="input" value="#{currentUser.password}" />
                     </p:input> <p:input id="confirm" label="Confirm password">
                          <h:inputSecret id="input"
                               value="#{passwordManager.confirmPassword}" />
                     </p:input>
      
                     <div class="buttonBox"><h:commandButton id="change"
                          value="Change" action="#{passwordManager.changePassword}" />
                     #{' '} <h:button id="cancel" value="Cancel" outcome="/index.xhtml" /></div>
                     </fieldset>
                     <s:validateForm id="passwordCheck" validatorId="confirmPasswordValidator"
                          fields="password=new:input confirmPassword=confirm:input" />
                </h:form></div>
      
           </ui:define>
      
           <ui:define name="sidebar">
                <div class="content">
                <h1>Simple things should be easy</h1>
                <p>(And so should some complex things.) You shouldn't have to
                write four different classes just to change a password. Traditional
                J2EE architectures require that developers spend more time writing
                code to make the frameworks happy, than they ever get to spend writing
                code to make the user happy. Seam lets you reduce the size of your
                code dramatically. And that reduces bugs. And it makes refactoring
                easier. And it makes delivering new functionality quicker.
                Productivity matters. But with Seam, JSF, EJB 3.0 and jBPM, you don't
                need to sacrifice the ability to handle complex problems just to
                achieve great productivity.</p>
                </div>
           </ui:define>
      
      </ui:composition>