0 Replies Latest reply on Jun 20, 2008 11:23 PM by infinity2heaven

    working with org.jboss.seam.exception.exceptions, faces messages, pages.xml

    infinity2heaven

      When an OptimisticLockException (or other critical exception) is thrown, it's caught by Seam and redirected in pages.xml. The error msg is displayed just fine. However, I also have a 'successful message' in facesMesages configured (either in pages.xml or via SFSB -- doesnt matter). The problem is, when the exception occurs, both these messages are printed! (I'm using <h:messages>) I added a check in pages.xml with the inbuilt seam component as shown below, but #{exceptions.handlers == null}" always resolves to true. With Seam managed persistent context, I know there is 'delay' in executing em.merge() and the actual flush, but how do we know when the exception occurs. What's the piece of code I need to write to see that state?


      SFSB


      @FlushMode(value=FlushModeType.COMMIT)
      public void save() {                        
         entityManager.merge(foo);                         
      }



      pages.xml


      <page view-id="/foo.xhtml">
        <action if="#{validation.failed}" execute="#{foo.invalid}"/>            
       <navigation from-action="#{foo.save}">
        <rule if="#{exceptions.handlers == null}">      
             <redirect view-id="/foo.xhtml">
                  <message severity="INFO">
                     Monthly Data updated successfully by #{identity.username} at #{myUtils.currentDate}
                  </message>
             </redirect>
         </rule>             
        <rule if="#{exceptions.handlers != null}">      
             <redirect view-id="/foo.xhtml">
                  <message severity="INFO">
                     Cannot update data
                  </message>
             </redirect>
         </rule>         
        </navigation>     
      </page>
      
       ....
      ...
        <exception class="javax.persistence.OptimisticLockException">
          <end-conversation/>
          <redirect view-id="#{redirect.viewId}">
            <message severity="ERROR">Data has been changed by another user, Get the most current data with a new search and proceed with your changes</message>
          </redirect>
        </exception>
       



            
      Also,this wont work still doesnt get caught in the catch block (only by Seam at runtime)



      @FlushMode(value=FlushModeType.COMMIT)
      public void save() {      
        try {
         entityManager.merge(foo);     
         entityManager.flush();
         }
         catch(RuntimeException e) {
          // never gets caught   
         }   
      }