1 2 Previous Next 27 Replies Latest reply on Apr 12, 2006 6:20 AM by Mirko Adari

    Using hibernate validator.

    Mirko Adari Novice

      Could you please give us some explanation how to exacly use
      Hibernate validator in Seam?

        • 1. Re: Using hibernate validator.
          Mirko Adari Novice

          I just can`t get it work.

          I have this in my .xhtml page:

          <h:message for="login"/><br />
           <h:outputLabel for="login" value="Kasutaja"/>
           <h:inputText id="login" value="#{current.login}"/>
          <h:commandButton id="submit" value="Muuda" action="#{usersList.done}"/>
          
          

          And this in my Entity bean:
          @Range(min=4,max=16,message="loginLength")
           public String getLogin() {
           return login;
           }
           public void setLogin(String login) {
           this.login = login;
           }

          And this in my userlist bean:
           @IfInvalid(outcome=REDISPLAY)
           public String done() {
           return "nothing";
           }
          


          But when I hit the commandLink it gives me this exception page:
          21:11:56,635 ERROR [[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception
          java.lang.IllegalStateException: Could not commit transaction
           at org.jboss.seam.jsf.SeamExtendedManagedPersistencePhaseListener.commit(SeamExtendedManagedPersistencePhaseListener.java:83)
           at org.jboss.seam.jsf.SeamExtendedManagedPersistencePhaseListener.afterPhase(SeamExtendedManagedPersistencePhaseListener.java:49)
           at org.apache.myfaces.lifecycle.LifecycleImpl.informPhaseListenersAfter(LifecycleImpl.java:536)
           at org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:318)
           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.component.html.util.ExtensionsFilter.doFilter(ExtensionsFilter.java:122)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
           at org.jboss.seam.servlet.SeamRedirectFilter.doFilter(SeamRedirectFilter.java:23)
           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.CustomPrincipalValve.invoke(CustomPrincipalValve.java:54)
           at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:174)
           at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:514)
           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:868)
           at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
           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: org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=nuclearbomb/455, BranchQual=, localId=455] status=STATUS_NO_TRANSACTION; - nested throwable: (org.hibernate.validator.InvalidStateException: validation failed for: ee.digizone.entity.PortalUser)
           at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:369)
           at org.jboss.tm.TxManager.commit(TxManager.java:239)
           at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:140)
           at org.jboss.seam.jsf.SeamExtendedManagedPersistencePhaseListener.commit(SeamExtendedManagedPersistencePhaseListener.java:77)
           ... 31 more
          Caused by: org.hibernate.validator.InvalidStateException: validation failed for: ee.digizone.entity.PortalUser
           at org.hibernate.validator.event.ValidateEventListener.validate(ValidateEventListener.java:104)
           at org.hibernate.validator.event.ValidateEventListener.onPreUpdate(ValidateEventListener.java:132)
           at org.hibernate.action.EntityUpdateAction.preUpdate(EntityUpdateAction.java:209)
           at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:64)
           at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:243)
           at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:227)
           at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
           at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
           at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
           at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1009)
           at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:356)
           at org.hibernate.transaction.CacheSynchronization.beforeCompletion(CacheSynchronization.java:59)
           at org.jboss.tm.TransactionImpl.doBeforeCompletion(TransactionImpl.java:1488)
           at org.jboss.tm.TransactionImpl.beforePrepare(TransactionImpl.java:1107)
           at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:321)
           ... 34 more
          

          So how can I tell him to redirect me to this same page and show that message?
          Shouldn`t IfInvalid do this?

          • 2. Re: Using hibernate validator.
            Gavin King Master

            You probably need to add @Valid to the reference from the session bean to the entity bean.

            Look at the examples.

            • 3. Re: Using hibernate validator.
              Mirko Adari Novice

              @Out(required=false)
              @Valid
              @DataModelSelection
              private PortalUser current;

              Have it.

              • 4. Re: Using hibernate validator.
                eekboom Newbie

                @Range is meant for numeric values, is that what you want? I suppose @Length is what you need instead.

                What are the annotations on the class declaration of your user bean?

                I think the error indicates that seam did not check the check the values at all (no jsf integration), but only pure hibernate validation was done?!

                But I also spent my day fighting hibernate, seam, adf, jsf, jboss, oracle, ... and I am not sure about this particular error.

                • 5. Re: Using hibernate validator.
                  Mirko Adari Novice

                  Thanks for pointing that out.
                  LEngth is what I need.
                  But this does not change nothing.
                  It still does not refreshi this page and show me errors.
                  Only that exception page is displayed.

                  • 6. Re: Using hibernate validator.
                    Mirko Adari Novice

                    @Entity
                    @Name("current")
                    @Table(name = "USERS")
                    public class PortalUser implements Serializable {
                    Annotations of my class.
                    It`s scope should be CONVERSATIONAL, at least Seam shows that is.

                    • 7. Re: Using hibernate validator.
                      Mirko Adari Novice

                      Seems that others are facing this issue as well.
                      So what`s the solution/problem Gavin?

                      • 8. Re: Using hibernate validator.
                        Gavin King Master

                        Um, which others?

                        The solution is to carefully follow the provided examples....

                        • 9. Re: Using hibernate validator.
                          Mirko Adari Novice

                          Okay I will give all code that atm I try to put working.
                          Btw exception has been changed... but I do not know what i changed. Still exception is accoured when hibernate validation failes.

                          Exception:

                          avax.faces.FacesException: Error calling action method of component with id _id32:submit
                           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.component.html.util.ExtensionsFilter.doFilter(ExtensionsFilter.java:122)
                           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
                           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
                           at org.jboss.seam.servlet.SeamRedirectFilter.doFilter(SeamRedirectFilter.java:23)
                           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.CustomPrincipalValve.invoke(CustomPrincipalValve.java:54)
                           at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:174)
                           at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:514)
                           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:868)
                           at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
                           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: /haldus/user.xhtml @44,74 action="#{usersList.done}": javax.ejb.EJBTransactionRolledbackException: java.lang.NullPointerException
                           at com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBinding.java:73)
                           at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)
                           ... 32 more
                          Caused by: javax.ejb.EJBTransactionRolledbackException: java.lang.NullPointerException
                           at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:89)
                           at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
                           at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:196)
                           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                           at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
                           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                           at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:81)
                           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                           at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
                           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                           at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
                           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                           at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
                           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                           at org.jboss.ejb3.stateful.StatefulContainer.localInvoke(StatefulContainer.java:190)
                           at org.jboss.ejb3.stateful.StatefulLocalProxy.invoke(StatefulLocalProxy.java:98)
                           at $Proxy217.done(Unknown Source)
                           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 com.sun.el.parser.AstValue.invoke(AstValue.java:130)
                           at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
                           at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
                           at com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBinding.java:69)
                           ... 33 more
                          Caused by: java.lang.NullPointerException
                           at org.jboss.seam.interceptors.ValidationInterceptor.refreshInvalidEntity(ValidationInterceptor.java:82)
                           at org.jboss.seam.interceptors.ValidationInterceptor.validateTargetComponent(ValidationInterceptor.java:56)
                           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.jboss.seam.util.Reflections.invoke(Reflections.java:13)
                           at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:87)
                           at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:60)
                           at org.jboss.seam.interceptors.OutcomeInterceptor.interceptOutcome(OutcomeInterceptor.java:21)
                           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.jboss.seam.util.Reflections.invoke(Reflections.java:13)
                           at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:87)
                           at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:60)
                           at org.jboss.seam.interceptors.RollbackInterceptor.rollbackIfNecessary(RollbackInterceptor.java:30)
                           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.jboss.seam.util.Reflections.invoke(Reflections.java:13)
                           at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:87)
                           at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:60)
                           at org.jboss.seam.interceptors.BijectionInterceptor.bijectTargetComponent(BijectionInterceptor.java:32)
                           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.jboss.seam.util.Reflections.invoke(Reflections.java:13)
                           at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:87)
                           at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:60)
                           at org.jboss.seam.interceptors.ConversationInterceptor.endOrBeginLongRunningConversation(ConversationInterceptor.java:58)
                           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.jboss.seam.util.Reflections.invoke(Reflections.java:13)
                           at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:87)
                           at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:60)
                           at org.jboss.seam.interceptors.BusinessProcessInterceptor.manageBusinessProcessContext(BusinessProcessInterceptor.java:58)
                           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.jboss.seam.util.Reflections.invoke(Reflections.java:13)
                           at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:87)
                           at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:60)
                           at org.jboss.seam.interceptors.RemoveInterceptor.removeIfNecessary(RemoveInterceptor.java:38)
                           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.jboss.seam.util.Reflections.invoke(Reflections.java:13)
                           at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:87)
                           at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:60)
                           at org.jboss.seam.ejb.SeamInterceptor.aroundInvokeInContexts(SeamInterceptor.java:66)
                           at org.jboss.seam.ejb.SeamInterceptor.aroundInvoke(SeamInterceptor.java:38)
                           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.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:120)
                           at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:62)
                           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                           at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:57)
                           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                           at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
                           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                           at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
                           ... 56 more
                          



                          Entity Bean User:
                          package ee.digizone.entity;
                          
                          import java.io.Serializable;
                          import java.util.List;
                          
                          import javax.persistence.CascadeType;
                          import javax.persistence.Column;
                          import javax.persistence.Entity;
                          import javax.persistence.GeneratedValue;
                          import javax.persistence.GenerationType;
                          import javax.persistence.Id;
                          import javax.persistence.JoinColumn;
                          import javax.persistence.JoinTable;
                          import javax.persistence.ManyToMany;
                          import javax.persistence.Table;
                          
                          import org.hibernate.validator.Length;
                          import org.hibernate.validator.NotNull;
                          import org.hibernate.validator.Pattern;
                          import org.hibernate.validator.Range;
                          
                          import org.jboss.seam.annotations.Name;
                          import org.jboss.seam.annotations.datamodel.DataModel;
                          
                          @Entity
                          @Name("current")
                          @Table(name = "USERS")
                          public class PortalUser implements Serializable {
                          
                           private static final long serialVersionUID = 757145940869029044L;
                          
                           private Integer id;
                           private String login;
                           private String password;
                           private String firstname;
                           private String surname;
                           private String email;
                           @DataModel
                           private List<PortalRole> roles;
                          
                           public PortalUser() {}
                          
                           /* TODO: constructor kasutaja loomiseks.
                           * public PortalUser(String name, String Password, String login) { }
                           */
                          // @Pattern(regex="([a-zA-Z0-9-])+",message="firstnameError")
                           public String getFirstname() {
                           return firstname;
                           }
                           public void setFirstname(String firstname) {
                           this.firstname = firstname;
                           }
                          
                          // Pattern tuleb üle vaadata
                          // @Pattern(regex="^([a-zA-Z0-9_.-+])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$",
                          // message="emailPattern")
                           public String getEmail() {
                           return email;
                           }
                           public void setEmail(String email) {
                           this.email = email;
                           }
                          
                           @Id @GeneratedValue(strategy=GenerationType.AUTO)
                           @Column(name = "PORTALUSER_ID")
                           public Integer getId() {
                           return id;
                           }
                           public void setId(Integer id) {
                           this.id = id;
                           }
                          
                          
                           @Length(min=4,max=16,message="loginLength")
                           public String getLogin() {
                           return login;
                           }
                           public void setLogin(String login) {
                           this.login = login;
                           }
                          // @NotNull
                          // @Range(min=6,message="pwLength")
                           public String getPassword() {
                           return password;
                           }
                           public void setPassword(String password) {
                          /* Tundub, et POJO arvab teisiti, teeme teisiti
                           * try
                           {
                           byte[] hash =
                           /MessageDigest.getInstance("SHA").digest(password.getBytes("UTF8"));
                           this.password = Util.encodeBase64(hash);
                           }
                           catch(Exception e)
                           {
                           e.printStackTrace();
                           }
                           */
                           this.password = password;
                           }
                          // @Pattern(regex="([a-zA-Z0-9-])+",message="surnameError")
                           public String getSurname() {
                           return surname;
                           }
                           public void setSurname(String surname) {
                           this.surname = surname;
                           }
                          
                           @ManyToMany(cascade = { CascadeType.MERGE, CascadeType.PERSIST,
                           CascadeType.REFRESH },targetEntity=PortalRole.class)
                           @JoinTable(name = "portaluser_portalrole", joinColumns = @JoinColumn(name = "portaluser_id"), inverseJoinColumns = @JoinColumn(name = "portalrole_id"))
                           public List<PortalRole> getRoles() {
                           return roles;
                           }
                          
                           public void setRoles(List<PortalRole> roles) {
                           this.roles = roles;
                           }
                          }
                          


                          UserListBean:
                          //$Id: UsersListBean.java,v 1.3 2006/04/04 10:59:59 adari Exp $
                          package ee.digizone.ejb;
                          
                          import static javax.persistence.PersistenceContextType.EXTENDED;
                          import static org.jboss.seam.annotations.Outcome.REDISPLAY;
                          
                          import java.util.List;
                          
                          import javax.ejb.Interceptors;
                          import javax.ejb.Remove;
                          import javax.ejb.Stateful;
                          import javax.ejb.TransactionAttribute;
                          import javax.ejb.TransactionAttributeType;
                          import javax.persistence.EntityManager;
                          import javax.persistence.PersistenceContext;
                          
                          import org.hibernate.validator.Valid;
                          import org.jboss.seam.ScopeType;
                          import org.jboss.seam.annotations.Begin;
                          import org.jboss.seam.annotations.Conversational;
                          import org.jboss.seam.annotations.Destroy;
                          import org.jboss.seam.annotations.End;
                          import org.jboss.seam.annotations.Factory;
                          import org.jboss.seam.annotations.IfInvalid;
                          import org.jboss.seam.annotations.In;
                          import org.jboss.seam.annotations.Name;
                          import org.jboss.seam.annotations.Out;
                          import org.jboss.seam.annotations.Scope;
                          import org.jboss.seam.annotations.datamodel.DataModel;
                          import org.jboss.seam.annotations.datamodel.DataModelSelection;
                          import org.jboss.seam.ejb.SeamInterceptor;
                          
                          import ee.digizone.entity.PortalUser;
                          
                          @Stateful
                          @Name("usersList")
                          @Scope(ScopeType.SESSION)
                          @Interceptors(SeamInterceptor.class)
                          
                          public class UsersListBean implements UsersList
                          {
                           @DataModel
                           private List<PortalUser> users;
                          
                           @In(required=false)
                           @Out(required=false)
                           @DataModelSelection
                           @Valid
                           private PortalUser current;
                          
                           @PersistenceContext
                           private EntityManager entityManager;
                          
                           @SuppressWarnings("unchecked")
                           @Factory("users")
                           public String findUsers(){
                           users = (List<PortalUser>) entityManager.createQuery(
                           "from PortalUser u order by surname,firstname asc"
                           ).getResultList();
                           return "";
                           }
                           public String delete() {
                           users.remove(current);
                           entityManager.remove(current);
                           current=null;
                           return "users";
                           }
                           @Begin(join=true)
                           public String select() {
                           return "user";
                           }
                          
                           @IfInvalid(outcome=REDISPLAY, refreshEntities=true)
                          // @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
                           public String done() {
                           return "nothing";
                           }
                           @Remove @Destroy
                           public void destroy() {}
                          }
                          

                          users.xhtml - page to select editable user:
                          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                          <html xmlns="http://www.w3.org/1999/xhtml"
                           xmlns:ui="http://java.sun.com/jsf/facelets"
                           xmlns:h="http://java.sun.com/jsf/html"
                           xmlns:f="http://java.sun.com/jsf/core"
                           xmlns:t="http://myfaces.apache.org/tomahawk"
                           xmlns:s="http://jboss.com/products/seam/taglib">
                          <body>
                          <ui:composition template="templates/layout.xhtml">
                           <ui:define name="body">
                           <h:form>
                           <b><s:link view="/haldus/users.xhtml" value="Nimekiri" /></b>
                           <h:outputText> Muuda kasutajat </h:outputText>
                           <s:link view="/haldus/cuser.xhtml" value="Loo uus" />
                           <br />
                           <h:outputText value="Kasutajad puuduvad" rendered="#{users.rowCount==0}"/>
                           <t:dataTable var="u" value="#{users}" rendered="#{users.rowCount>0}">
                           <h:column>
                           <f:facet name="header">
                           <h:outputText value="Isik"/>
                           </f:facet>
                           <h:commandLink action="#{usersList.select}">
                           <h:outputText value="
                           #{u.firstname}
                            
                           #{u.surname}"/>
                           </h:commandLink>
                           </h:column>
                           <h:column>
                           <f:facet name="header">
                           <h:outputText value="Kasutaja"/>
                           </f:facet>
                           (
                           <h:commandLink value="#{u.login}" action="#{usersList.select}" />
                           )
                           </h:column>
                           <h:column>
                           <f:facet name="header">
                           <h:outputText value="E-post"/>
                           </f:facet>
                           <h:outputText value="#{u.email}" />
                           </h:column>
                           <h:column>
                           <h:commandButton value="Kustuta" action="#{usersList.delete}"/>
                           </h:column>
                           </t:dataTable>
                           </h:form>
                           </ui:define>
                          </ui:composition>
                          </body>
                          </html>
                          

                          Edit user page:
                          <?xml version="1.0" encoding="iso-8859-15"?>
                          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                          <html xmlns="http://www.w3.org/1999/xhtml"
                           xmlns:ui="http://java.sun.com/jsf/facelets"
                           xmlns:h="http://java.sun.com/jsf/html"
                           xmlns:f="http://java.sun.com/jsf/core"
                           xmlns:s="http://jboss.com/products/seam/taglib">
                          <body>
                          <ui:composition template="templates/layout.xhtml">
                           <ui:define name="body">
                           <s:link view="/haldus/users.xhtml" value="Nimekiri" />
                           <b>
                           <s:link view="/haldus/user.xhtml"> Muuda kasutajat </s:link>
                           </b>
                           <s:link view="/haldus/cuser.xhtml" value="Loo uus" />
                           <br /> <br />
                           <h:form>
                           <fieldset>
                           <div class="entry">
                           <h:message for="login"/><br />
                           <h:outputLabel for="login" value="Kasutaja"/>
                           <h:inputText id="login" value="#{current.login}"/>
                           </div><br />
                           <div class="entry">
                           <h:outputLabel for="password" value="Salasõna:"/>
                           <h:inputText id="password" value=""/>
                           </div><br />
                           <div class="entry">
                           <h:outputLabel for="spassword" value="Korda salasõna:"/>
                           <h:inputText id="spassword" value=""/>
                           </div><br />
                           <div class="entry">
                           <h:outputLabel for="firstname" value="Eesnimi:"/>
                           <h:inputText id="firstname" value="#{current.firstname}"/>
                           </div><br />
                           <div class="entry">
                           <h:outputLabel for="surname" value="Perekonnanimi:"/>
                           <h:inputText id="surname" value="#{current.surname}"/>
                           </div><br />
                           <div class="entry">
                           <h:outputLabel for="email" value="E-post"/>
                           <h:inputText id="email" value="#{current.email}"/>
                           </div><br />
                           <h:commandButton id="submit" value="Muuda" action="#{usersList.done}"/>
                           </fieldset>
                           </h:form>
                           </ui:define>
                          </ui:composition>
                          
                          </body>
                          </html>


                          • 10. Re: Using hibernate validator.
                            Mirko Adari Novice

                            Seems to me, that usual error printing does work now.
                            It seems to be a case of using @persistenceContext(Type.EXTENDED) and
                            extendedpersistenceseamlistener together. If I removed that Type.EXTENDED it started to work.
                            But what about this refreshentities feature? I really need that no incorrect
                            data will not be flushed to database. Without it, invalid value is flushed.
                            This works:
                            @IfInvalid(outcome=REDISPLAY)
                            This gives exception in last post:
                            @IfInvalid(outcome=REDISPLAY,refresihEntities=true)

                            • 11. Re: Using hibernate validator.
                              Gavin King Master

                              You have:

                              @PersistenceContext
                              private EntityManager entityManager;


                              and:

                              @IfInvalid(outcome=REDISPLAY, refreshEntities=true)


                              You *cannot* use refreshEntities=true with an EJB-managed persistence context, you must instead use a Seam-managed persistence context.

                              However, the NPE Seam throws is actually my bug, it should throw a meaningful exception instead.


                              • 12. Re: Using hibernate validator.
                                Mirko Adari Novice

                                Okay, this REFRESHENTITIES does not work, but I did get this subject working as i wanted it.

                                • 13. Re: Using hibernate validator.
                                  Mirko Adari Novice

                                  How can I use Seam-managed persistence context?
                                  I use

                                  <phase-listener>org.jboss.seam.jsf.SeamExtendedManagedPersistencePhaseListener</phase-listener>

                                  listener for seam.

                                  • 14. Re: Using hibernate validator.
                                    Mirko Adari Novice

                                    Sorry, I have missed section in manual.

                                    1 2 Previous Next