4 Replies Latest reply on Dec 19, 2006 4:21 AM by eekboom

    @NotNull annotation not working...

    Waheed murad Newbie

      i am working on registration form and i want that user cannot submit empty fields. i have marked the corresponding fields with @NotNull annotation in the Entity POJO but its not working. Other annotations @length etc are working fine. when form is submitted with empty fields, the session bean method is invoked and i have the following errors.


      00:18:40,095 INFO [STDOUT] Hibernate: select EREGCUSTOMER_SEQ.nextval from dual
      00:18:40,563 ERROR [[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception
      javax.faces.FacesException: Error calling action method of component with id registercustomerform:create
      at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:74)
      at javax.faces.component.UICommand.broadcast(UICommand.java:106)
      at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:90)
      at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:164)
      at org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:316)
      at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:86)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:106)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:144)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
      at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
      at java.lang.Thread.run(Thread.java:595)
      Caused by: javax.faces.el.EvaluationException: Exception while invoking expression #{customerAction.registerCustomer}
      at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:153)
      at org.jboss.seam.actionparam.ActionParamBindingHelper.invokeTheExpression(ActionParamBindingHelper.java:58)
      at org.jboss.seam.actionparam.ActionParamMethodBinding.invoke(ActionParamMethodBinding.java:71)
      at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)
      ... 27 more
      Caused by: java.lang.RuntimeException: org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=liberty/31, BranchQual=, localId=31] status=STATUS_NO_TRANSACTION; - nested throwable: (javax.persistence.PersistenceException: org.hibernate.validator.InvalidStateException: validation failed for: org.com.pojo.ERegCustomer)
      at org.jboss.aspects.tx.TxPolicy.handleEndTransactionException(TxPolicy.java:198)
      at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:180)
      at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)
      at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:197)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:81)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.ejb3.stateful.StatefulContainer.localInvoke(StatefulContainer.java:188)
      at org.jboss.ejb3.stateful.StatefulLocalProxy.invoke(StatefulLocalProxy.java:98)
      at $Proxy168.registerCustomer(Unknown Source)
      at org.com.eventreg.ERegCustomerLocal$$FastClassByCGLIB$$176dc401.invoke()
      at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
      at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:47)
      at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:67)
      at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:57)
      at org.jboss.seam.interceptors.SynchronizationInterceptor.serialize(SynchronizationInterceptor.java:31)
      at sun.reflect.GeneratedMethodAccessor165.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.jboss.seam.util.Reflections.invoke(Reflections.java:17)
      at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:172)
      at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:66)
      at org.jboss.seam.intercept.RootInterceptor.invokeInContexts(RootInterceptor.java:168)
      at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:141)
      at org.jboss.seam.intercept.RootInterceptor.aroundInvoke(RootInterceptor.java:128)
      at org.jboss.seam.intercept.ClientSideInterceptor.interceptInvocation(ClientSideInterceptor.java:60)
      at org.jboss.seam.intercept.ClientSideInterceptor.intercept(ClientSideInterceptor.java:47)
      at org.com.eventreg.ERegCustomerLocal$$EnhancerByCGLIB$$5d429574.registerCustomer()
      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 org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:129)
      ... 30 more
      Caused by: org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=liberty/31, BranchQual=, localId=31] status=STATUS_NO_TRANSACTION; - nested throwable: (javax.persistence.PersistenceException: org.hibernate.validator.InvalidStateException: validation failed for: org.com.pojo.ERegCustomer)
      at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:372)
      at org.jboss.tm.TxManager.commit(TxManager.java:240)
      at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:175)
      ... 69 more
      Caused by: javax.persistence.PersistenceException: org.hibernate.validator.InvalidStateException: validation failed for: org.com.pojo.ERegCustomer
      at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:487)
      at org.jboss.tm.TransactionImpl.doBeforeCompletion(TransactionImpl.java:1491)
      at org.jboss.tm.TransactionImpl.beforePrepare(TransactionImpl.java:1110)
      at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:324)
      ... 71 more
      Caused by: org.hibernate.validator.InvalidStateException: validation failed for: org.com.pojo.ERegCustomer
      at org.hibernate.validator.event.ValidateEventListener.validate(ValidateEventListener.java:104)
      at org.hibernate.validator.event.ValidateEventListener.onPreInsert(ValidateEventListener.java:127)
      at org.hibernate.action.EntityInsertAction.preInsert(EntityInsertAction.java:139)
      at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:44)
      at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
      at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
      at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
      at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:993)
      at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:340)
      at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:475)
      ... 74 more

      --------------------------
      any advise Plz
      Thanks in advacnce

        • 1. Re: @NotNull annotation not working...
          Stephan Bublava Newbie

          You probably need to add required="true" to the form input components. Otherwise empty values won't be validated by JSF.

          Thanks,
          Stephan

          • 2. Re: @NotNull annotation not working...
            Waheed murad Newbie

            thanks Stephan for quick reply.

            if i will add required="true" to the form input components then it will be checked by the JSF not by Jboss Seam or hibernate validators (in my case @NotNull) i want the validation to be performed on server side through annotations on my Entity bean.

            • 3. Re: @NotNull annotation not working...
              Waheed murad Newbie

              well i have understood the problem but cannot find solution for it.. well i have

              h:outputText in my JSF page as

              <h:inputText id="username" value="#{customer.username}">

              which is mapped to the Entity bean

              Entity
              @Name("customer")
              @Scope(SESSION)
              @Table(name="ERegCustomer")
              @SequenceGenerator(name="CUSTOMER_SEQUENCE", sequenceName="EREGCUSTOMER_SEQ")
              public class ERegCustomer implements Serializable
              {

              private static final long serialVersionUID = 1881413500711441953L;

              private Integer id;
              private String username;
              private String password;
              ....
              ....
              ....

              And my session bean as
              public class ERegCustomerAction implements ERegCustomerLocal {

              @In
              private Context sessionContext;

              @In(required=false)
              @Out(required=false)
              private ERegCustomer customer;

              public String registerCustomer()
              {
              .......
              .........
              ......... /// here customer.getUsername returns empty String not null

              when i submit the form with empty field, ........ customer.username have value. i mean it is assigined to empty string ("") not to null so abviously @NotNull anotation will not work. if this is the case then for what @NotNull is used for and if i am right then what mistake i made

              • 4. Re: @NotNull annotation not working...
                eekboom Newbie

                I think you should use @Length(min=1) instead.
                Empty fields give zero length strings rather than null strings.