3 Replies Latest reply on Jan 31, 2011 8:38 PM by kragoth

    Using @PostConstruct, interceptors and Seam 2.2.1.CR2

    kragoth

      OK, let me preface this by saying the code I am about to put in this post worked FINE in Seam 2.0.1 - CR1.


      My problem is this. I have an interceptor that intercepts all my Seam beans on the @PostConstruct event. See Code below.


      
      @Interceptor(stateless = true)
      public class GekkoSeamLifecycleInterceptor extends AbstractInterceptor {
      
          @PostConstruct
          public void postConstruct(InvocationContext invocation) throws Exception { //NOPMD
              Logger log = LogManager.getLogger(this.getClass().getSimpleName() + "."
                  + getLogCategory(invocation.getTarget()));
              
              if (invocation.getTarget() instanceof AbstractSeamComponent) {
                  AbstractSeamComponent abstractSeamComponent = 
                      ((AbstractSeamComponent)invocation.getTarget());
                  abstractSeamComponent.setConversationId(
                      Conversation.instance().getId());
              }
      
              log.debug("Seam Bean of type: "
                  + invocation.getTarget().getClass().getCanonicalName()
                  + " has been created. In conversation: " + Conversation.instance().getId());
          }
      
          @Override
          public Object aroundInvoke(InvocationContext ic) throws Exception { //NOPMD
              return ic.proceed();
          }
          
          @Override
          public boolean isInterceptorEnabled()
          {
             return true;
          }
      ...other bits and pieces that are not relevant.
      }
      



      Today I tried to update to Seam 2.2.1.CR2 and things have not gone well. The PostConstruct method does not work anymore! Why doesn't the PostConstruct annotated method get invoked? I've been trying for the best part of a day using google and just trying random combinations of changes to get something to happen but, no luck.


      I'll just show how I use the interceptor and hope that someone else has had this problem and solved it.


      I have my own annotation:


      @Target(TYPE)
      @Retention(RUNTIME)
      @Inherited
      @Interceptors(GekkoSeamLifecycleInterceptor.class)
      public @interface LifecycleInterceptor {}
      



      which is used the superclass of all my Seam beans.


      @SpringAutowirable
      @ExceptionInterceptor
      @LifecycleInterceptor
      public class AbstractSeamComponent implements Serializable {
      



      This was working perfectly fine in Seam 2.0.1. If anyone knows how to get this going again that would be great. Or, is it a known issue with this version of Seam?

        • 1. Re: Using @PostConstruct, interceptors and Seam 2.2.1.CR2
          kragoth

          Well, after spending almost an entire day trying to work out what changed between 2.0.1 and 2.2.1 that would make my interceptor stop working I was just about ready to give up and revert back to using Seam 2.0.1.


          In a last ditch effort I decided to just jam the @PostConstruct method onto my AbstractSeamComponent (my superclass of all Seam beans in my app) and see if I could get my app going that way.


          So, in my Abstract superclass I put this method


          @PostConstruct
          public void seamHackBecauseItsBugged() {
              //LEAVE THIS ALONE. Seam 2.2.1-CR2 will not call the
              // @PostConstruct method in the GekkoSeamLifecycleInterceptor 
              // if this method isn't here.
              log.debug("Post Construct Method fired");
          }
          



          So, I expected to see a bunch of Post Construct Method fired lines in my log file. But, when I looked there were none. BUT, (now here comes the strange part) my @PostConstruct method of my interceptor was now working again!


          So, the @PostConstruct method on my superclass never gets executed. However by having it there the @PostConstruct method on my interceptor starts working again.


          I guess the question now is why? Why does my @PostConstruct method in my interceptor only fire iff there is a method annotated with @PostConstruct on my Seam bean even though the  @PostConstruct on my Seam bean doesn't get executed.


          Is there any point in raising a JIRA for this? Does anyone still even look at the Seam 2.x.x codebase anymore?

          • 2. Re: Using @PostConstruct, interceptors and Seam 2.2.1.CR2
            pouria62
            here is my java code which i wish it check my checkbox but it didnt.

                    private long positionTypeId;

            public long getPositionTypeId() {
              if (this.positionType != null)
               return this.getPositionType().getId();
              else
               return 0;
            }

            public void setPositionTypeId(long value) {
              this.positionTypeId = value;

              this.positionType = this.entityManager.find(PositionType.class,
                this.positionTypeId);
                 this.selectedOptions.clear();
                 for (PositionTypeSeverity sev : this.positionType.getPositionTypeSeverity()) {
               Long sev_id = sev.getId();
                   this.selectedOptions.add(sev_id);
              }
                 }

            <h:form id="positionTypeSeverityAdd" styleClass="edit">
            <rich:panel>
               <h:panelGrid>
            <h:outputText value="#{positionTypeSeverityConversation.positionType.name}" />

            <h:selectManyCheckbox id="severity" value="#{positionTypeSeverityConversation.selectedOptions}">
            <s:selectItems var="_ser" value="#{positionTypeSeverityConversation.severities}"
            label="#{_ser.name}" itemValue="#{_ser.id}" />
            </h:selectManyCheckbox>
            </h:panelGrid>
            </rich:panel>

            <h:commandButton id="save" value="Save"
            action="#{positionTypeSeverityConversation.save()}"
            style="FONT-FAMILY: 'Abyssinica SIL';">
            </h:commandButton>

            <s:button view="/setting/hr/PositionType.xhtml" id="cancelAdd"
            value="Cancel">
            <f:param name="positionTypeId" value="#{positionTypeId}" />
            </s:button>
            </h:form>
            • 3. Re: Using @PostConstruct, interceptors and Seam 2.2.1.CR2
              kragoth

              This has nothing to do with my problem and you have already asked this question in another thread. Please do not do this. It is rude and unprofessional.