title: Scope in JSF Validator
body: <p>I I want to implement input filed validation. This is the code of the managed bean:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8' ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"    
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:ui="http://java.sun.com/jsf/facelets"&gt;
      &lt;h:head&gt;
          &lt;ui:insert name="header"&gt;           
              &lt;ui:include src="header.xhtml"/&gt;         
          &lt;/ui:insert&gt;
      &lt;/h:head&gt;
      &lt;h:body&gt;
  
          &lt;h1&gt;&lt;img src="resources/css/images/icon.png" alt="NVIDIA.com" /&gt; History Center&lt;/h1&gt;
          &lt;!-- layer for black background of the buttons --&gt;
          &lt;div id="toolbar" style="margin: 0 auto; width:1180px; height:30px; position:relative;  background-color:black"&gt;
              &lt;!-- Include page Navigation --&gt;
              &lt;ui:insert name="Navigation"&gt;           
                  &lt;ui:include src="Navigation.xhtml"/&gt;         
              &lt;/ui:insert&gt;
  
          &lt;/div&gt;  
  
          &lt;div id="logodiv" style="position:relative; top:35px; left:0px;"&gt; 
              &lt;h:graphicImage alt="Demo Insert Form"  style="position:relative; top:-20px; left:9px;"  value="resources/images/logo_databasez.png" /&gt;
          &lt;/div&gt;
          &lt;div id="main" style="margin: 0 auto; width:1190px; height:700px; position:absolute;  background-color:transparent; top:105px"&gt;
  
              &lt;div id="mainpage" style="margin: 0 auto; width:1190px; height:500px; position:absolute;  background-color:transparent; top:80px"&gt;
  
                  &lt;div id="settingsHashMap" style="width:350px; height:400px; position:absolute;  background-color:r; top:20px; left:1px"&gt;
                      &lt;h:form&gt;
                          &lt;div id="settingsdiv" style="width:750px; height:400px; position:absolute;  background-color:r; top:20px; left:1px"&gt;
  
                              &lt;h:panelGrid columns="2"&gt;
                                  &lt;h:panelGroup&gt;Session ID&lt;/h:panelGroup&gt;
                                  &lt;h:panelGroup&gt;
                                      &lt;h:inputText id="sessionid" value="#{DatabaseController.formMap['sessionid']}" &gt;
                                          &lt;f:validateLength minimum="0" maximum="15"/&gt;
                                          &lt;f:validator binding="#{ValidatorController.validateMessage}" &gt;
                                              &lt;f:attribute name="type" value="sessionid" /&gt;
                                          &lt;/f:validator&gt;
                                          &lt;f:ajax event="blur" render="sessionidvalidate" /&gt;                                          
                                      &lt;/h:inputText&gt;
                                      &lt;h:message id="sessionidMessage" for="sessionid" /&gt;
                                  &lt;/h:panelGroup&gt;
  
                                  &lt;h:panelGroup&gt;User ID&lt;/h:panelGroup&gt;
                                  &lt;h:panelGroup&gt;
                                      &lt;h:inputText id="userid" value="#{DatabaseController.formMap['userid']}" &gt;
                                          &lt;f:validateLength minimum="0" maximum="15"/&gt;
                                      &lt;/h:inputText&gt;
                                  &lt;/h:panelGroup&gt;
  
                                  &lt;h:panelGroup&gt;Login Time&lt;/h:panelGroup&gt;
                                  &lt;h:panelGroup&gt;
                                      &lt;h:inputText id="logintime" value="#{DatabaseController.formMap['logintime']}" &gt;
                                          &lt;f:validateLength minimum="0" maximum="35"/&gt;
                                      &lt;/h:inputText&gt;
                                  &lt;/h:panelGroup&gt;
  
                                  &lt;h:panelGroup&gt;Last Refresh Time&lt;/h:panelGroup&gt;
                                  &lt;h:panelGroup&gt;
                                      &lt;h:inputText id="lastrefreshtime" value="#{DatabaseController.formMap['lastrefreshtime']}" &gt;
                                          &lt;f:validateLength minimum="0" maximum="35"/&gt;
                                      &lt;/h:inputText&gt;
                                  &lt;/h:panelGroup&gt;
  
                                  &lt;h:panelGroup&gt;User IP&lt;/h:panelGroup&gt;
                                  &lt;h:panelGroup&gt;
                                      &lt;h:inputText id="userip" value="#{DatabaseController.formMap['userip']}" &gt;
                                          &lt;f:validateLength minimum="0" maximum="15"/&gt;
                                      &lt;/h:inputText&gt;
                                  &lt;/h:panelGroup&gt;
  
                              &lt;/h:panelGrid&gt;          
  
                          &lt;/div&gt;   
  
                          &lt;div id="settingstwodiv" style="width:150px; height:60px; position:absolute;  background-color:transparent; top:380px; left:800px"&gt;
  
                              &lt;h:commandButton value="Create User" action="#{DatabaseController.saveData}"/&gt;
  
                          &lt;/div&gt; 
                      &lt;/h:form&gt; 
  
                  &lt;/div&gt;   
  
              &lt;/div&gt;  
          &lt;/div&gt;
  
      &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is the code that I added into faces-config.xml</p>
  
  <pre><code>&lt;validator&gt;
      &lt;validator-id&gt;ValidatorController&lt;/validator-id&gt;
      &lt;validator-class&gt;com.DX_57.HM_57.FormValidator&lt;/validator-class&gt;
  &lt;/validator&gt;
  </code></pre>
  
  <p>This is the code of the Validator that I tried to test:</p>
  
  <pre><code>import javax.enterprise.context.SessionScoped;
  import javax.faces.application.FacesMessage;
  import javax.faces.component.UIComponent;
  import javax.faces.context.FacesContext;
  import javax.faces.validator.Validator;
  import javax.faces.validator.ValidatorException;
  import javax.inject.Named;
  
  @Named("ValidatorController")
  @SessionScoped
  public class FormValidator implements Validator {
  
      public FormValidator() {
      }
  
      @Override
      public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
          throw new UnsupportedOperationException("Not supported yet.");
      }
  
      public void validateMessage(FacesContext context, UIComponent component, Object value) throws ValidatorException {
  
          if (value.equals("test")) {
              throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR,
                      "Session ID is already in use, please choose another.", null));
          }
      }
  }
  </code></pre>
  
  <p>The problem is this error that I get when I try to run the example:</p>
  
  <pre><code>[#|2012-05-05T22:39:00.096+0300|INFO|glassfish3.1.2|org.glassfish.osgiweb|_ThreadID=58;_ThreadName=Thread-2;|Removed bundle 710 against context path /test |#]
  
  [#|2012-05-05T22:39:00.097+0300|WARNING|glassfish3.1.2|org.glassfish.osgijavaeebase|_ThreadID=58;_ThreadName=Thread-2;|Failed to deploy bundle com.DX_57.History-Module-57 [710]
  org.glassfish.osgijavaeebase.DeploymentException: Deployment of com.DX_57.History-Module-57 [710] failed because of following reason: Failed while deploying bundle com.DX_57.History-Module-57 [710] : java.lang.RuntimeException: Failed to deploy bundle [ com.DX_57.History-Module-57 [710] ], root cause: Exception while loading the app
      at org.glassfish.osgijavaeebase.AbstractOSGiDeployer.deploy(AbstractOSGiDeployer.java:125)
      at org.glassfish.osgijavaeebase.OSGiContainer.deploy(OSGiContainer.java:154)
      at org.glassfish.osgijavaeebase.JavaEEExtender.deploy(JavaEEExtender.java:107)
      at org.glassfish.osgijavaeebase.JavaEEExtender.access$200(JavaEEExtender.java:61)
      at org.glassfish.osgijavaeebase.JavaEEExtender$HybridBundleTrackerCustomizer$1.call(JavaEEExtender.java:151)
      at org.glassfish.osgijavaeebase.JavaEEExtender$HybridBundleTrackerCustomizer$1.call(JavaEEExtender.java:148)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
      at java.util.concurrent.FutureTask.run(FutureTask.java:166)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
      at java.lang.Thread.run(Thread.java:722)
  Caused by: java.lang.RuntimeException: Failed to deploy bundle [ com.DX_57.History-Module-57 [710] ], root cause: Exception while loading the app
      at org.glassfish.osgijavaeebase.OSGiDeploymentRequest.deploy(OSGiDeploymentRequest.java:196)
      at org.glassfish.osgijavaeebase.OSGiDeploymentRequest.execute(OSGiDeploymentRequest.java:118)
      at org.glassfish.osgijavaeebase.AbstractOSGiDeployer.deploy(AbstractOSGiDeployer.java:121)
      ... 10 more
  Caused by: org.glassfish.deployment.common.DeploymentException: WELD-000072 Managed bean declaring a passivating scope must be passivation capable.  Bean:  Managed Bean [class com.DX_57.HM_57.FormValidator] with qualifiers [@Any @Default @Named]
      at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:181)
      at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:128)
      at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:277)
      at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:460)
      at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
      at org.glassfish.osgijavaeebase.OSGiDeploymentRequest.deploy(OSGiDeploymentRequest.java:183)
      ... 12 more
  Caused by: org.jboss.weld.exceptions.DefinitionException: WELD-000072 Managed bean declaring a passivating scope must be passivation capable.  Bean:  Managed Bean [class com.DX_57.HM_57.FormValidator] with qualifiers [@Any @Default @Named]
      at org.jboss.weld.bean.ManagedBean.checkType(ManagedBean.java:405)
      at org.jboss.weld.bean.AbstractBean.initializeAfterBeanDiscovery(AbstractBean.java:149)
      at org.jboss.weld.bean.AbstractClassBean.initializeAfterBeanDiscovery(AbstractClassBean.java:308)
      at org.jboss.weld.bean.ManagedBean.initializeAfterBeanDiscovery(ManagedBean.java:361)
      at org.jboss.weld.bootstrap.BeanDeployment.doAfterBeanDiscovery(BeanDeployment.java:216)
      at org.jboss.weld.bootstrap.BeanDeployment.afterBeanDiscovery(BeanDeployment.java:208)
      at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:352)
      at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:179)
      ... 17 more
  |#]
  </code></pre>
  
  <p>It seems that the Validator class is not in the correct scope. What scope I have to use?</p>
  
  <p>Best Wishes</p>