Uploaded image for project: 'Seam Faces'
  1. Seam Faces
  2. SEAMFACES-185

Add support for activating beans based on the JSF project stage

    Details

    • Type: Feature Request
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 3.0.2
    • Fix Version/s: 3.1.0.Beta4
    • Component/s: None
    • Labels:
      None

      Description

      Hey all,

      I think it would be a great enhancement if Seam Faces could support activation of beans only in specific JSF project stages. MyFaces CODI supports a similar feature with the @ProjectStageActivated annotation.

      Examples:

      @ProductionStage
      @ApplicationScoped
      public class ProductionEntityManagerProducer {
        ...
      }
       
      @DevelopmentStage
      @ApplicationScoped
      public class DevelopmentEntityManagerProducer {
        ...
      }
      

      Another very interesting usecase would be to enable specific interceptors/decorators only in development stage. This could be used for debugging stuff that is only interesting during development.

      I think this could be easily implenented using an CDI extension that vetos beans that do not match the active project stage. The only problem I'm seeing is that we will need the JSF project stage in an very early stage during application startup (actually before JSF started up). This means that we would have to determine the project stage JSF will use ourselves.

      The JSF spec describes that the project stage can either be set with a servlet context parameter or using JNDI. If the latter one is uses, we could simply do a JNDI lookup in the extension. No problem here. If the developer uses a servlet context parameter the situation will become more problematic, because we will need a reference to the ServletContext in the extension.

      What do you think of this feature? Would it be useful? Any further ideas for the implementation?

        Gliffy Diagrams

          Activity

          Hide
          chkal Christian Kaltepoth added a comment -

          Hey Brian! Thank you very much for reviewing and merging my patch. I'm glad to hear you like it!

          Show
          chkal Christian Kaltepoth added a comment - Hey Brian! Thank you very much for reviewing and merging my patch. I'm glad to hear you like it!
          Hide
          blabno Bernard Labno added a comment -

          I've tried this cool feature, but can't make it work. I'm setting up the stage using JNDI (AS7.1.0.Beta1) with following entry in web.xml:
          <resource-env-ref>
          <resource-env-ref-name>jsf/ProjectStage</resource-env-ref-name>
          <resource-env-ref-type>java.lang.String</resource-env-ref-type>
          <lookup-name>java:/jsf/ProjectStage</lookup-name>
          </resource-env-ref>
          During bean processing by extension the java:comp/env/jsf/ProjectStage is not available, thus extension always thinks it's Production phase.

          Show
          blabno Bernard Labno added a comment - I've tried this cool feature, but can't make it work. I'm setting up the stage using JNDI (AS7.1.0.Beta1) with following entry in web.xml: <resource-env-ref> <resource-env-ref-name>jsf/ProjectStage</resource-env-ref-name> <resource-env-ref-type>java.lang.String</resource-env-ref-type> <lookup-name>java:/jsf/ProjectStage</lookup-name> </resource-env-ref> During bean processing by extension the java:comp/env/jsf/ProjectStage is not available, thus extension always thinks it's Production phase.
          Hide
          chkal Christian Kaltepoth added a comment -

          Hey Bernard,

          thanks for bringing this up.

          you wrote that the JNDI entry is not available during the extension processing. Did you confirm this by looking at the TRACE logs? If so, could you post them? It would also be interesting to know if the lookup works if it is done after the application has started from an action method or something like that.

          Thanks

          Christian

          Show
          chkal Christian Kaltepoth added a comment - Hey Bernard, thanks for bringing this up. you wrote that the JNDI entry is not available during the extension processing. Did you confirm this by looking at the TRACE logs? If so, could you post them? It would also be interesting to know if the lookup works if it is done after the application has started from an action method or something like that. Thanks Christian
          Hide
          blabno Bernard Labno added a comment -

          For now I can only tell you that my observations are from debugging (i've put breakpoints). So during bean processing the JNDI seems to be not set yet but later on i.e. during commandButton click in JSF app the "java:comp/env/jsf/ProjectStage" is correctly set in JNDI.

          Show
          blabno Bernard Labno added a comment - For now I can only tell you that my observations are from debugging (i've put breakpoints). So during bean processing the JNDI seems to be not set yet but later on i.e. during commandButton click in JSF app the "java:comp/env/jsf/ProjectStage" is correctly set in JNDI.
          Hide
          chkal Christian Kaltepoth added a comment -

          Thanks for sharing your observations. For me it looks like this may be a problem with AS7 then. I'll try to build an Arquillian test that reproduces this.

          Show
          chkal Christian Kaltepoth added a comment - Thanks for sharing your observations. For me it looks like this may be a problem with AS7 then. I'll try to build an Arquillian test that reproduces this.

            People

            • Assignee:
              chkal Christian Kaltepoth
              Reporter:
              chkal Christian Kaltepoth
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development