4 Replies Latest reply on Dec 24, 2007 12:47 PM by ebu

    error message & trinidad

    ebu

      hi,
      i can't get error messages displayed in seamdiscs-based app. when validator is being triggered i'm getting

      Caused by: org.hibernate.validator.InvalidStateException: validation failed for: bu.test.shop.Property
       at org.hibernate.validator.event.ValidateEventListener.validate(ValidateEventListener.java:143)
       at org.hibernate.validator.event.ValidateEventListener.onPreInsert(ValidateEventListener.java:167)
       at org.hibernate.action.EntityIdentityInsertAction.preInsert(EntityIdentityInsertAction.java:119)
       at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:42)
      
      ...
      20:01:12,671 ERROR [[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception
      java.lang.IllegalStateException
       at org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:435)
       at javax.servlet.http.HttpServletResponseWrapper.sendRedirect(HttpServletResponseWrapper.java:126)
       at org.jboss.seam.web.RedirectFilter$1.sendRedirect(RedirectFilter.java:69)
       at org.jboss.seam.mock.MockExternalContext.redirect(MockExternalContext.java:520)
       at org.jboss.seam.faces.FacesManager.redirect(FacesManager.java:197)
       at org.jboss.seam.faces.FacesManager.redirect(FacesManager.java:167)
       at org.jboss.seam.faces.Navigator.redirect(Navigator.java:46)
       at org.jboss.seam.exception.RedirectHandler.handle(RedirectHandler.java:51)
       at org.jboss.seam.exception.Exceptions.handle(Exceptions.java:75)
       at org.jboss.seam.web.ExceptionFilter.endWebRequestAfterException(ExceptionFilter.java:114)
       at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:70)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:44)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      


      just on screen instead of nice error message.

      The view is like this:

       <tr:form>
       <s:validateAll>
       <f:facet name="afterInvalidField">
       <tr:outputText value="FFF" />
       </f:facet>
       <tr:panelFormLayout>
       <tr:inputText label="Properties" value="#{propertyHome.instance.name}" required="true" />
       </tr:panelFormLayout>
       <tr:panelFormLayout>
       <tr:selectOneChoice value="#{propertyHome.instance.type}" required="true" >
       <s:selectItems value="#{propertyHome.propertyTypes}" var="propertyType" label="#{propertyType.label}" noSelectionLabel="Please select" />
       <s:convertEnum />
       </tr:selectOneChoice>
       </tr:panelFormLayout>
       </s:validateAll>
      <h:commandButton action="#{propertyHome.update}" value="Save" rendered="#{propertyHome.managed}" />
      


      the model class:

      @Entity
      public class Property {
      ...
       @NotNull(message = "zzz") //not acctually used. trinidad (or something else?) displays it's own error message when input isn't filled
       @Length(max = 3, message="YYY")
       private String name;
      
      


      would be greatly thankfull if somebody could point at what i'm missing.

      wbr, eugene.


        • 1. Re: error message & trinidad
          pmuir

          Use your debugger to find out why a ModelValidator isn't being attached to the input control (it should be) by putting a breakpoint in ValidateAllRendererBase.doEncodeChildren

          • 2. Re: error message & trinidad
            ebu

            it is indeed, otherwise there would be no InvalidStateException. The problem appeared to be quite obvious - this exception just was not catched. After reading validation part of seam ref i somehow decided that seam cares about catching validation exception itself. But as it became clear after studying dvd example it doesn't. Thus after adding an interceptor around my bean i got my messages in place:

             try {
             return ctx.proceed();
            
             } catch (InvalidStateException e) {
             InvalidValue[] vals = e.getInvalidValues();
             for (InvalidValue val: vals) {
             FacesMessages.instance().add(val);
             }
             Transaction.instance().setRollbackOnly();
            
             return null;
             }
            


            the only problem i still have is that trinidads inputText tag doesn't want to show messages forcing me to use h:inputTag with h:message instead...
            Havn't somebody had some issues with using trinidad to display messages?

            wbr, eugene.

            • 3. Re: error message & trinidad
              pmuir

               

              "ebu" wrote:
              it is indeed, otherwise there would be no InvalidStateException. The problem appeared to be quite obvious - this exception just was not catched. After reading validation part of seam ref i somehow decided that seam cares about catching validation exception itself.


              No, completely wrong. The InvalidStateException is thrown by hibernate as it tries to persist the invalid entity. The ModelValidator checks for *potentially invalid* values *before* the entity is persisted. So the reason you get the InvalidStateException is that the ModelValidator isn't running during the JSF validation phase, the error, therefore isn't being reported to JSF and is instead thrown when you flush the persistence context.


              the only problem i still have is that trinidads inputText tag doesn't want to show messages forcing me to use h:inputTag with h:message instead...
              Havn't somebody had some issues with using trinidad to display messages?


              Try doing it properly using s:validate... As I said, check why the ModelValidator isn't being attached by s:validateAll.

              • 4. Re: error message & trinidad
                ebu

                eh, that was old facelets lib... http://jira.jboss.com/jira/browse/JBSEAM-1667

                but your explanations about model validator are very helpful. Would be nice to have them in ref. doc.

                Thanks!