1 Reply Latest reply on Apr 20, 2011 10:38 AM by fernando_jmt

    How to avoid Seam Faces' TransactionPhaseListener being installed as a bean

    fernando_jmt

      Hi,


      I'm using seam-persistence, seam-faces and seam-xml 3.0.0.Final in Tomcat 7 using JTA, and it is working fine if I don't catch exceptions in the beans. But when I try to do so, because Seam Faces' TransactionPhaseListener is commiting the transactions,  none of my beans' actions can catch the persistence exception and then return an appropriate outcome. So this simple catch doesn't work if Seam Faces's TransactionPhaseListener is enabled:


      public String update() {
              try {
                  service.merge(model);
              } catch (Exception e) {
                  System.out.println("Exceptions caught" + e);
              }
              return "List";
      }





      If I remove seam-faces from classpath I can catch the exception correctly, but I want seam faces for events propagations, messages and some other nice stuff. So what I need is just to avoid the installation of TransactionPhaseListener as a bean. I'm using seam-xml too, and according the documentation, the use of s:replaces tag configuration in seam-beans.xml should do the work :



      <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:s="urn:java:ee"
             xmlns:t="urn:java:org.jboss.seam.transaction"
             xmlns:f="urn:java:org.jboss.seam.faces.transaction"
             xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://docs.jboss.org/cdi/beans_1_0.xsd">
      
          <t:SeSynchronizations>
              <s:modifies/>
          </t:SeSynchronizations>
      
          <t:UTTransaction>
              <s:modifies/>
          </t:UTTransaction>
      
          <f:TransactionPhaseListener>
              <s:replaces/>
          </f:TransactionPhaseListener>
      
      </beans>




      Above configuration doesn't work because it seems TransactionPhaseListener is still being installed incorrectly because in the application I get the following exception (TransactionPhaseListener is being called):



      java.lang.IllegalStateException: Could not start transaction
              at org.jboss.seam.faces.transaction.TransactionPhaseListener.begin(TransactionPhaseListener.java:96)
              at org.jboss.seam.faces.transaction.TransactionPhaseListener.begin(TransactionPhaseListener.java:86)
              at org.jboss.seam.faces.transaction.TransactionPhaseListener.handleTransactionsBeforePhase(TransactionPhaseListener.java:67)
              at org.jboss.seam.faces.transaction.TransactionPhaseListener.beforePhase(TransactionPhaseListener.java:49)
              at org.jboss.seam.faces.event.DelegatingPhaseListener.beforePhase(DelegatingPhaseListener.java:28)
              at com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:228)
              at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:99)
              at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:111)
              at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
              at org.jboss.seam.servlet.exception.CatchExceptionFilter.doFilter(CatchExceptionFilter.java:65)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
              at org.jboss.seam.servlet.event.ServletEventBridgeFilter.doFilter(ServletEventBridgeFilter.java:72)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
              at org.apache.catalina.core.StandardWrapperValve.__invoke(StandardWrapperValve.java:240)
              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java)
              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
              at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
              at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
              at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:306)
              at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:323)
              at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1719)
              at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
              at java.lang.Thread.run(Thread.java:619)
      Caused by: java.lang.NullPointerException
              at org.jboss.seam.faces.transaction.TransactionPhaseListener.begin(TransactionPhaseListener.java:91)
              ... 32 more




      So is there something I'm missing using the <s:replaces>? The <veto> tag was mentioned here, but it seems that is not present in 3.0.0.Final version.


      Thanks in advance for your help.







        • 1. Re: How to avoid Seam Faces' TransactionPhaseListener being installed as a bean
          fernando_jmt

          Solved. After digging a bit on examples and code I've found that adding a new qualifier to the default TransactionPhaseListener works pretty well.





          <?xml version="1.0" encoding="UTF-8"?>
          <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xmlns:s="urn:java:ee" xmlns:t="urn:java:org.jboss.seam.transaction"
                 xmlns:ft="urn:java:org.jboss.seam.faces.transaction"
                 xmlns:sc="urn:java:org.jboss.seam.solder.core"
                 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://docs.jboss.org/cdi/beans_1_0.xsd">
              <t:SeSynchronizations>
                  <s:modifies/>
              </t:SeSynchronizations>
              <t:UTTransaction>
                  <s:modifies/>
              </t:UTTransaction>
              <sc:Veto>
                  <s:Qualifier/>
              </sc:Veto>
              <ft:TransactionPhaseListener>
                  <s:replaces/>
                  <sc:Veto/>
              </ft:TransactionPhaseListener>
          </beans>