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

    Problem with hibernate validator

    Andre Lode Newbie

      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 ...