1 Reply Latest reply on Jul 8, 2010 3:03 PM by billevans

    a4j:push - Same PushEventListener given to different instances

    billevans

      I am using a4j:push extensively to have pages be updated automatically by the server.  However, I have hit the following issue:  When two different instances of the same page initiate a push they end up using the same instance of the PushEventListener.  The effect of this is that only one of the pages actually receives the update event.

       

      Here is the code I put in the pages:

       

          <a4j:region>
              <a4j:push id="asyncPusher" eventProducer="#{accountDetail.addListener}" interval="${identity.pageAutoUpdateInterval}"
                        reRender="#{accountDetail.unsolicitedUpdIds}" limitToList="false"
                        oncomplete="showApplErrorDialogIfExists();">   
                  </a4j:push>                                
          </a4j:region>

       

      And the method I have in my java action class:

       

          public void addListener(EventListener listener) {
              this.listener = (PushEventListener) listener;
              EventManager.instance().addListener(this, this.identity);
          }

       

       

      When two instances of the page come up then both call the addListener method but the listener they are passed is the exact same one (ie.their identityHashCodes are the same).   Therefore when it comes to firing the onEvent(...)  for both pages, only one page is actually updated.

       

      This is a show-stopper problem for me, so I'd love it if the experts can show me a way around...

       

      Thanks.

        • 1. Re: a4j:push - Same PushEventListener given to different instances
          billevans

          In case anyone out there is intested, I did find a solution to this after getting a hint from JBoss support.  The trick is to use the 'binding' attribute to force a unique ID to be generated:

           

          e.g.

                    <a4j:push id="#{pushWrapper.push.id}" binding="#{pushWrapper.push}" 
                            eventProducer="#{accountDetail.addListener}" interval="${identity.pageAutoUpdateInterval}"
                            reRender="#{accountDetail.unsolicitedUpdIds}" limitToList="false"
                            oncomplete="showApplErrorDialogIfExists();">   
                </a4j:push>
             
                                   

           

           

          Then you need to write an Event-scoped bean to support the binding:


          @Name("pushWrapper")
          @Scope(ScopeType.EVENT)
          public class PushRequest {
              private static final Log log = new Log4JSeamAwareProvider(PushRequest.class);

           

              private UIPush push = new AjaxPush();   
            
              public PushRequest() {
              }   
             
              public UIPush getPush() {
                  return this.push;
              }


              @Create
              public void onCreate() {       
                  log.info("On create");
                  Conversation conv = Conversation.instance();
                  if (conv != null) {
                      String cid = conv.getId();
                      this.push.setId(cid);
                  }
              }
              public void setPush(UIPush push) {
                  this.push = push;
              }
          }