0

Event Queue subscribe and ViewModel re-init

asked 2015-07-20 16:40:38 +0800

WilliamB gravatar image WilliamB
1609 1 6

updated 2015-07-21 10:25:39 +0800

I used Event queue to communicate between View Models as I cannot use GlobalCommand that would trigger multiple instances of one of my ViewModel.

I'm using a different event queue for each of my instance and it works fine. In the Init, I lookup that event queue and also subscribe to a new SerializableEventListener<event>.

@Init(superclass = true)
public void init() {
    eq = EventQueues.lookup(tabEventQueue);

    eq.subscribe(new SerializableEventListener<Event>() {

        private static final long serialVersionUID = 1L;

        @Override
        public void onEvent(final Event pEvent) throws Exception {

            if (pEvent.getName().equals(MY_EVENT_NAME)) {
                // Do something
            }
        }
    });
}

However when the use navigate in my application, he ll rego through init if he leave the page and comes back. Thus I end up subscribing multiple time to the event.

How can I avoid that multiple register?

delete flag offensive retag edit
Be the first one to answer this question!
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2015-07-20 16:40:38 +0800

Seen: 16 times

Last updated: Jul 21 '15

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More