5 Replies Latest reply on Jan 24, 2013 4:17 AM by mkouba

    Exception handling Seam 2.3 (JBoss 7)

    joshd

      I try to understand the exception handling behavior - without success so far..

       

       

      I have to browsers open (Safari and Firefox) and load the entity detail form for the same entity in both browsers. This edit form starts a LRC. Then I submit the first form (dao.merge()) and then the second. Of course that fails because of optimistic locking (@Version annotation on the "int version" attribute of entity). Now of course at least I want the user to be informed about that. The according exception handler in the pages.xml is present,

       

      {code}  <exception class="javax.persistence.OptimisticLockException">

              <end-conversation/>

               <redirect view-id="/error.xhtml">

                   <message severity="error">Error message..</message>

               </redirect>

           </exception>

          <exception>

               <redirect view-id="/error.xhtml">

                   <message severity="error">Unexprected error, please try again</message>

               </redirect>

           </exception>

      {code}

       

      Case 1: works


      I have  a

       

      {code:xml}<p:ajax event="blur" update="nameEdit" partialSubmit="true"/>{code}

       

      on the name-field of the entity. So - after I've submitted the first form - when I change the name here I get the expected javax.persistence.OptimisticLockException (as first in trace) onBlur, the exception-handler matched, I see the error.xhtml - everthing ok.

       

       

      Case 2: doesnt work


      I remove the validation ajax-onblur-event. After submitting form no. 1 changing the name field in form no. 2 und press

       

      {code:xml}<p:commandButton

              id="update"

              action="#{entityAction.save}"

              value="#{messages['base.action.save']}"                                   

              icon="ui-icon-check"

              update=":mainform" />

      {code}

       

      The first exception in console is a javax.ejb.EJBTransactionRolledbackException  (first causedBy OptimisticLock, second causedBy StaleObject). But no exception handler at all is stepping in. And then the application is not reacting on ajax calls anymore (APPLICATION ERROR: transaction still active in request with status 0).

       

      Can anybody help me with whats wrong here?

        • 1. Re: Exception handling Seam 2.3 (JBoss 7)
          mkouba

          Don't you have Seam debug mode (components.xml) or Facelets development mode enabled (JSF param javax.faces.FACELETS_DEVELOPMENT in web.xml)?

          • 2. Re: Exception handling Seam 2.3 (JBoss 7)
            joshd

            Thanks... yeah, I know that the debug mode(s) needs to be off for exeption handling working correctly. However.. I 've tried both.. but case no. 2 (my post) it is not working anyway.

             

            Since one is working and the other doesn't - what is the reason for the exception handler not to catch. Does the exception type in handler definition need to match the very first exception in trace? But defining an EJBTransactionRolledbackException could not be the solution, because it doesnt let me know "why" it was thrown.

            • 3. Re: Exception handling Seam 2.3 (JBoss 7)
              mkouba
              Does the exception type in handler definition need to match the very first exception in trace?
              

              I think so. Only if the last exception in the stack (the final exception thrown by the app) is assignable to the type specified in the exception element the handler is matched. However if you don't specify the class attribute the handler should match any exception (and you have it defined :-)... so that you should see error.xhtml anyway.

               

              How is your Seam filter mapped? It's possible the mapping is somehow broken and the filter is not applied - see also http://docs.jboss.org/seam/2.3.0.Final/reference/en-US/html/events.html#d0e5607.

              • 4. Re: Exception handling Seam 2.3 (JBoss 7)
                joshd

                However if you don't specify the class attribute the handler should match any exception (and you have it defined :-)... so that you should see error.xhtml anyway.

                 

                 

                No, thats the thing.. just nothing happend in the described case 2.  Exception handling gererally works, as described in case 1.. also for other exception handlers I've added (EntityNotFound, Authorization etc.).

                 

                 

                Filter web.xml

                {code:xml}

                <filter>

                      <filter-name>Seam Filter</filter-name>

                      <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>

                    </filter>

                 

                    <filter-mapping>

                      <filter-name>Seam Filter</filter-name>

                      <url-pattern>/*</url-pattern>

                    </filter-mapping>   

                {code}

                 

                components.xml:

                {code:xml}

                <web:exception-filter url-pattern="*.vt"/>

                {code}

                (also FacesServlet, web:mulitpart, web:redirect - it is all mapped to the *.vt extension)

                 

                For now I just removed the optmistic locking, but this isn't a solution.

                • 5. Re: Exception handling Seam 2.3 (JBoss 7)
                  mkouba

                  This bug is apparently related: https://issues.jboss.org/browse/JBSEAM-5045...