5 Replies Latest reply on Nov 17, 2008 1:52 AM by majeric

    implementation of PushEventListener

      Hi,

      I have implemented PushEventListener as folows:

      class MyPushEventListener implements PushEventListener {
       public void onEvent(EventObject evt) {
       System.out.println(evt.getSource());
       }
      }


      How to use this listener now in my thread? If I do like this:
      public class Test extends Thread {
      ...
      private MyPushEventListener listener;
      public void addListener(EventListener listener) {
       synchronized (listener) {
       if (this.listener != listener) {
       this.listener = ((MyPushEventListener) listener);
       }
       }
       }
      ..
      }

      I get an error
      org.ajax4jsf.webapp.PushEventsCounter cannot be cast to develop.MyPushEventListener


      Does anyone now how to make this work?
      I just need to call my own onEvent() method which is implemented in MyPushEventListener.

      Thanks

        • 1. Re: implementation of PushEventListener

          anyone? I would realy need this, ASAP.

          Thanks.

          • 2. Re: implementation of PushEventListener
            nbelaevski

            Hi,

            As you can see there are some other listeners that a4j:push component adds to event producer for its purposes. Implement addListener() method to hold a list of listeners, but not only the single listener of your type.

            • 3. Re: implementation of PushEventListener

               

              Implement addListener() method to hold a list of listeners, but not only the single listener of your type.


              How should I do that? I would appreciate any quick example.

              Thanks.

              • 4. Re: implementation of PushEventListener
                nbelaevski

                Try this:

                package test;
                
                import java.util.EventListener;
                import java.util.EventObject;
                import java.util.List;
                import java.util.concurrent.CopyOnWriteArrayList;
                
                import org.ajax4jsf.event.PushEventListener;
                
                public class Test extends Thread {
                 private List<PushEventListener> listeners = new CopyOnWriteArrayList<PushEventListener>();
                
                 public void addListener(EventListener listener) {
                 listeners.add((PushEventListener) listener);
                 }
                
                 /* (non-Javadoc)
                 * @see java.lang.Thread#run()
                 */
                 @Override
                 public void run() {
                 super.run();
                 for (PushEventListener listener : listeners) {
                 EventObject event = new EventObject(this);
                 listener.onEvent(event);
                 }
                 }
                
                
                }


                • 5. Re: implementation of PushEventListener

                  OK. Thanks for help. I'll try this solution.

                  Uros