2 Replies Latest reply on Mar 5, 2009 9:12 AM by alvarano

    Problem with hibernate validator

    alvarano

      Hello community,


      I'm a newbie in seam and I want to create a test application. Therefor I use hibernate and jpa as persistence layer, spring and icefaces with facelets. The application runs on a Tomcat 6.0 and the deployment process is done by maven. I want to validate the userinputs of an ice:form against the hibernate validator. The required=true attribute works fine but when I enter 2 digits for the zipCode (@Length(min = 3)) I get an

      org.hibernate.validator.InvalidStateException: validation failed for: poc_icefaces.model.User

      and the form site isn't redisplayed.


      Here is my code:


      UserServiceImpl.java



      @Name("userService")
      @Scope(ScopeType.CONVERSATION)
      @Transactional
      public class UserServiceImpl implements UserService {
      
              @In
              private EntityManager em;
      
              @In (required = false, scope = ScopeType.CONVERSATION)
              @Out(required = false, scope = ScopeType.CONVERSATION)
              private User user;
      
              @Begin
              public String editUser(User selectedUser) {
                      user = em.merge(selectedUser);
                      return "edit";
              }
      
              @End
              public void saveUser() {
                      em.persist(user);
              }




      User.java (entity):



      @Entity
      @Name("user")
      @Scope(ScopeType.CONVERSATION)
      public class User {
      
              private Long id;        
              private String zipCode;
              
              @Id @GeneratedValue
              public Long getId() {
                      return id;
              }
              public void setId(Long id) {
                      this.id = id;
              }
              
              ...
              
              @Length(min = 3)
              public String getZipCode() {
                      return zipCode;
              }
              public void setZipCode(String zipCode) {
                      this.zipCode = zipCode;
              }
      }




      editUser.jspx:



      <s:decorate>
        <h:inputText id="zipCode" value="#{user.zipCode}" required="true">
          <s:validate />
        </h:inputText>
        <h:message for="zipCode"/>                             
      </s:decorate>





      pages.xml:



      <page view-id="/protected/user/editUser.jspx">
        <action execute="#{userService.saveUser}" if="#{validation.succeeded}" />
      
        <navigation from-action="#{userService.saveUser}">
          <redirect view-id="/protected/user/userManagement.jspx" />
        </navigation>
      </page>





      I hope you can help me ...

        • 1. Re: Problem with hibernate validator
          jguglielmin

          Since you say you are new, you might want to consider first getting things going without Spring and then perhaps add it in once you are more comfortable?  There is an example of how to tie in your own ajax validation with hibernate validations and ICEfaces on the ICEfaces forum, jboss-seam Integration section  You may want to check it out (if you haven't already).   Please also view the use of decorator tag with a decorator template (already encompasses the s:validator tag). 
          For quicker response with anything regarding ICEfaces, you might want to post on the ICEfaces forum.  (or both to see if you can get different perspectives?).

          • 2. Re: Problem with hibernate validator
            alvarano

            Hello Judy,


            thx for your reply. In the ICEfaces forum I found the solution. I was missing the seam-ui dependency in my pom file. Now it works !!!