-
Notifications
You must be signed in to change notification settings - Fork 3
Pushing javascript to the client
uklance edited this page Aug 28, 2012
·
15 revisions
Custom javascript can be pushed to the client when an event is received using the AjaxResponseRenderer
TML
<t:cometd.PushTarget topic="/myTopic" event="messageReceived" update="replace" />
Java
@Inject
private AjaxResponseRenderer ajaxResponseRenderer;
@Inject
private Block messageBlock;
@Property
private String message;
Block onMessageReceived(final String message) {
ajaxResponseRenderer.addCallback(new JavaScriptCallback() {
public void run(JavaScriptSupport jss) {
jss.addScript("alert('%s')", message);
}
});
// returning a block is optional, this event handler could return void
this.message = message;
return messageBlock;
}