TimerPushService gets disconnected

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

TimerPushService gets disconnected

Mats
Hi,

I have a simple page with two tabs. When a tab is clicked the panel on the page is replaced. On the panels there are components that are using wicketstuff-push-timer to update there contents.

My problem: All works until I have clicked the tabs and the panel is replaced. Then the push service is disconnected and nothing is evermore updated...

Can someone point out what I have to do to get this working?

Se sample code below...



// This page shows two tab panels that has components updated via push
public class MyPage extends WebPage {

    private AjaxFallbackLink link1 = null;
    private AjaxFallbackLink link2 = null;
    private Panel1 panel1 = new Panel1("main"); // Uses the PanelBase class below
    private panel2 panel2 = new Panel2("main"); // Uses the PanelBase class below
    private Panel current = panel1;
   
    public MyPage() {
       
        // Create the milking tab
        link1 = new AjaxFallbackLink("tab_1") {
            // On "Milking" link click
            @Override
            public void onClick(AjaxRequestTarget target) {
                // Switch panels
                current.replaceWith(panel1);
                current = panel1;
                // Change style
                link1.add(new AttributeModifier("class", "tab_selected"));
                link2.add(new AttributeModifier("class", "tab"));
                // Update components
                target.add(current);
                target.add(link1);
                target.add(link2);
            }
        };

        // Create the cleaning tab
        link2 = new AjaxFallbackLink("tab_2") {

            // On "Cleaning" link click
            @Override
            public void onClick(AjaxRequestTarget target) {
                // Switch panels
                current.replaceWith(panel2);
                current = panel2;
                // Change style
                link1.add(new AttributeModifier("class", "tab"));
                link2.add(new AttributeModifier("class", "tab_selected"));
                // Update components
                target.add(current);
                target.add(link1);
                target.add(link2);
            }
        };

        // Add components
        add(link1);
        add(link2);
        add(current);

        // We like to update the components using Ajax
        link1.setOutputMarkupId(true);
        link2.setOutputMarkupId(true);
        panel1.setOutputMarkupId(true);
        panel2.setOutputMarkupId(true);
    }
}



// This is parts of the base class for components updated via push (included on the tab panels above)
public abstract class PanelBase extends Panel  {
   
    public PanelBase(String id) {
        super(id);
       
        // Instantiate push event handler
        final IPushEventHandler handler = new AbstractPushEventHandler<Message>() {
            @Override
            public void onEvent(AjaxRequestTarget target, Message message, IPushNode<Message> node, IPushEventContext<Message> ctx) {
                // PROBLEM: When the tab panels above has been replaced we never ever come here anymore!
                System.err.println("3. SHOW MESSAGE");
                onUpdate(target);
            }
        };

        // Obtain a reference to a Push service implementation
        final IPushService pushService = TimerPushService.get();

        // Install push node into this panel
        final IPushNode<Message> pushNode = pushService.installNode(this, handler);

        // Connect to the message service and forward the Message events to the push node and it's event handler
        IMessageService messageService = new IMessageService() {
            @Override
            public void onMsg(Message message) {
                onMessage(message);
                System.err.println("1. GOT MESSAGE");
                // PROBLEM: When the tab panels above has been replaced the push service seems to be disconnected...
                if (pushService.isConnected(pushNode)) {
                    // Forward the Message event via the push service to the push event handler
                    System.err.println("2. PUSH MESSAGE");
                    pushService.publish(pushNode, message);
                }
            }
        };
    }
}