4 Replies Latest reply on Apr 7, 2006 6:03 PM by Mirko Adari

    Forcing call of conversational component method on event

    d1g Newbie

      Hi Gavin (or Seam team),

      I need to force the calling of a conversational component method for every event/request related to that component. I have a work around (see below) but it would be nice if Seam could do this for me. Perhaps a new annotation (e.g. @Event) that can be applied to a method would work.

      If there is already a way to do this please let me know!

      Here is my work around.

      I've created an event scope field in my conversational SFSB.

      @Out(scope = ScopeType.EVENT)
      private String forceEventMethod;


      And then used a Seam factory annotation to populate this field and do the event work required.

      @Factory("forceEventMethod")
      public void eventMethod() {
       forceEventMethod = "called";
       // do stuff here
      }
      


      I then refer to this field in my view which forces the method to be called.

      <h:outputText rendered="#{forceEventMethod == 'called'}"></h:outputText>
      

      There is probably a more elegant way to achieve this...

      Bit of background: I need to check if the URL has been changed by the user before allowing the conversational component to populate the view with data. I am using url rewriting to hide parameters. This relates to another feature request (supplying urls to s:link tag) in the following post.

      http://www.jboss.com/index.html?module=bb&op=viewtopic&t=80643

      Is it possible to add a feature like this to Seam? Thanks in advance.


        • 1. Re: Forcing call of conversational component method on event
          Gavin King Master

          What does "every event/request related to that component" mean?

          You mean, every time a component is used? In that case, use an interceptor.

          I don't really understand.

          • 2. Re: Forcing call of conversational component method on event
            Mirko Adari Novice

            Basically you can do following and this gives you ability to choose, which pages you wan`t to enchance with this feature:
            pages.xml

            <page view-id"/somepage.jsp" action="#{component.method}" .../>


            I would use this one because in my applications I usually define conversation timeot by node and action would not be so hard to add.

            • 3. Re: Forcing call of conversational component method on event
              d1g Newbie

              Thanks mirko27. I'd forgotten the pages.xml file. This almost solves my problem except that the action gets called prior to the render response phase which is too late for me.

              From section 3.3 of the Seam reference.

              This action method is called at the beginning of the render response phase, any time the page is about to be rendered.


              If this action were called earlier (after restore view) then it would work for me. I guess this would no longer be an action though.

              Gavin, once my component has been created, after @Create, there is no way for the component to do something on subsequent requests, where no action has been called. The component is not used if the view is just rendered with no action call.

              To recap, I want to ensure a method in my component is called on every relevant request and view. I want a chance to change the state of the component and conversation.

              I may be able to use a mix of an interceptor and the pagex.xml file. I'll go away and think about this. Perhaps I'll reconsider my design. Thanks for the help.

              • 4. Re: Forcing call of conversational component method on event
                Mirko Adari Novice

                Well, I thought your situation over and this really is a design of Filter. Interceptor need`s to be called and is not tied to view. Implement some simple Filter. It voles all your problems very easilly and causes minimal load (much less then seam figuring out what and where to do)