4 Replies Latest reply on Jan 14, 2010 5:31 PM by asookazian

    Can CDI offer magic for PhaseListener impl?

    asookazian

      I have the following class which I want to be available/active during dev, not prod.


      @Name("lifeCycleListener")
      @Install(false)
      public class LifeCycleListener implements PhaseListener {
          
           private static final long serialVersionUID = 7280794517722311938L;
           
           private static Logger log = Logger.getLogger(LifeCycleListener.class);
      
           public PhaseId getPhaseId() {
              return PhaseId.ANY_PHASE;
          }
      
          public void beforePhase(PhaseEvent event) {
              log.info("LifeCycleListener: START PHASE " + event.getPhaseId());
          }
      
          public void afterPhase(PhaseEvent event) {
               log.info("LifeCycleListener: END PHASE " + event.getPhaseId());
          }
      
      }



      Is there any way to refactor this in CDI/Weld such that I can achieve this?  The @Install(false) did not block the class from being active, all that does is block it from being scanned and installed/managed by the Seam container as a Seam component. 


      Or perhaps this is simply a build issue (i.e. have ant or maven not include this class in the WAR/EAR if the build mode is 'prod').  But I was hoping for an elegant programmatic solution.


      thx.

        • 1. Re: Can CDI offer magic for PhaseListener impl?
          gavin.king

          No, there's not real integration between CDI and PhaseListeners.

          • 2. Re: Can CDI offer magic for PhaseListener impl?
            nickarls

            BTW, I mailed plaform/jsf feedback recently which resulted in issue 718

            • 3. Re: Can CDI offer magic for PhaseListener impl?
              asookazian

              I'm not suggesting or even really requesting for such integration to be added to the CDI spec, etc.  Unless it is appropriate and that is up to you guys.  But I thought that some way to configure this for dev/prod would be really cool (e.g. @Alternatives, etc.)  Otherwise, it becomes a PITA to handle this properly.


              NKarlsson, thx for creating the JSF issue!


              This is actually a general problem if you think about it.  It is a envmt config problem for classes in general, not just classes implementing JSF-specific interfaces like in this case.  How do we or should we handle this in EE 6?

              • 4. Re: Can CDI offer magic for PhaseListener impl?
                asookazian

                Now I just read the @Install annotation section in SiA book.  There is a debug attribute which indicates that the component should be installed only when Seam is operating in debug mode.


                I don't see an @Install here: http://java.sun.com/javaee/6/docs/api/


                So maybe in EE 7 there can be an @Install that has either the CDI or EJB container (or whatever container(s) that will be active for that spec/impl) install my LifeCycleListener if in the ejb-jar.xml or application.xml or beans.xml configs, etc. the debug flag is set to true.


                WDYT?


                Or is there such a concept already in EE 6?