I start supporting reload extension on my custom wicketstuff-push (see the post). Let's see the code.
public abstract class CometdAbstractBehavior extends AbstractDefaultAjaxBehavior { private static final long serialVersionUID = 1L; // FIXME: put this in application scope, we may have several webapp using // CometdBehavior in the same web container! private final static String cometdServletPath = getCometdServletPath(); private static final ResourceReference COMETD = new CompressedResourceReference(CometdAbstractBehavior.class, "org/cometd.js"); private static final ResourceReference JQ_JSON2 = new CompressedResourceReference(CometdAbstractBehavior.class, "jquery/json2.js"); private static final ResourceReference JQ_COMETD = new CompressedResourceReference(CometdAbstractBehavior.class, "jquery/jquery.cometd.js"); private static final ResourceReference COMETD_RELOAD = new CompressedResourceReference(CometdAbstractBehavior.class, "org/cometd/ReloadExtension.js"); private static final ResourceReference JQ_COOKIE = new CompressedResourceReference(CometdAbstractBehavior.class, "jquery/jquery.cookie.js"); private static final ResourceReference JQ_COMETD_RELOAD = new CompressedResourceReference(CometdAbstractBehavior.class, "jquery/jquery.cometd-reload.js"); @Override public void renderHead(final IHeaderResponse response) { super.renderHead(response); if (channelId == null) { throw new IllegalArgumentException("ChannelId in a CometdBehavior can not be null"); } response.renderJavascriptReference(COMETD); response.renderJavascriptReference(JQ_JSON2); response.renderJavascriptReference(JQ_COMETD); response.renderJavascriptReference(COMETD_RELOAD); response.renderJavascriptReference(JQ_COOKIE); response.renderJavascriptReference(JQ_COMETD_RELOAD); response.renderJavascript(getInitCometdScript(), "initCometd"); final String cometdInterceptorScript = getCometdInterceptorScript(); if (cometdInterceptorScript != null) { response.renderJavascript(cometdInterceptorScript, "Interceptor" + getBehaviorMarkupId()); } response.renderJavascript(getSubscriberScript(), "Subscribe" + getBehaviorMarkupId()); } protected final CharSequence getInitCometdScript() { return new PackagedTextTemplate(CometdBehavior.class, "CometdReloadInit.js").getString() + getConfigureCometdScript() + getHandshakeCometdScript(); }
I add a javascript file. This code is written based on the reload example for jQuery (here).
/* handshake listener to report client IDs */ $.cometd.addListener("/meta/handshake", function(message) { if (message.successful) { $('#previous').html(org.cometd.COOKIE.get('demoLastCometdID')); $('#current').html(message.clientId); org.cometd.COOKIE.set('demoLastCometdID', message.clientId, { 'max-age': 300, path : '/', expires: new Date(new Date().getTime() + 300 * 1000) }); } else { $('#previous').html('Handshake Failed'); $('#current').html('Handshake Failed'); } }); /* Setup reload extension */ $(window).unload(function() { $.cometd.reload(); });
Be care that this works on not only browser reloads, but also loading the same page with different parameters. It means, subscribing to the different channel also happens without handshake.