-
Notifications
You must be signed in to change notification settings - Fork 297
Push
sebthom edited this page Apr 6, 2011
·
3 revisions
NOTE: this documentation applies to wicket push version 1.4.16 or higher.
The Wicket Push project provides support for Reverse AJAX in Wicket applications and allows them to "push" partial Web page updates to the Web browser.
The push projects comes with two implementations:
-
push-timer: a polling based approach where the web page continuously polls the server for page updates via AJAX (similar to
AjaxSelfUpdatingTimerBehavior
) -
push-cometd: the web pages connects to the web application via a stateful Cometd channel on which the server sends update requests to the browser on demand. Note: Cometd requires the Servlet 3.0 specification.
- push-core
- push-timer
- push-cometd
<dependency>
<groupId>org.wicketstuff</groupId>
<artifactId>push-timer</artifactId>
<version>1.4.17</version>
</dependency>
<dependency>
<groupId>org.wicketstuff</groupId>
<artifactId>push-cometd</artifactId>
<version>1.4-SNAPSHOT</version>
</dependency>
<repository>
<id>wicketstuff-core-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
The general usage pattern of wicket-push is:
- Create a class implementing
IPushEventHandler
containing the logic that updates the UI when a Push event occurs. Such an event is usually raised by a background service, e.g. chat service raising a MessageReceivedEvent. - Obtain a reference to a
IPushService
implementation in your Wicket Panel. - Use the push service to install a push node holding a reference to your push event handler into one of the panel's components. This will add the required client-side push markup to that component.
- Add a listener to your (asynchronous) background service and forward the raised events via the Push service to your Push event handler. This will ensure that the update code is handled in the right Wicket HTTP request thread.
Here is an example:
/*
* panel constructor
*/
public ChatPanel()
{
// setup UI components ...
/*
* 1. instantiate push event handler
*/
IPushEventHandler handler = new AbstractPushEventHandler<Message>()
{
public void onEvent(AjaxRequestTarget target, Message message, IPushNode<Message> node, IPushEventContext<Message> ctx)
{
// TODO your component update logic goes here...
}
});
/*
* 2. obtain a reference to a Push service implementation
*/
IPushService pushService = TimerPushService.get();
/*
* 3. install push node into this panel
*/
IPushNode<Message> pushNode = pushService.installNode(this, handler);
/*
* 4. connect to the chat service and forward the Message events to the push node and it's event handler
*/
IChatService chatService = ServiceLocator.getChatService();
chatService.addListener(new IChatListener() {
public void onMessage(Message msg)
{
if (pushService.isConnected(pushNode))
// forward the Message event via the push service to the push event handler
pushService.publish(pushNode, msg);
else
chatService.removeListener(this);
}
});
}
Active:
- Rodolfo Hansen
- Sebastian Thomschke
Retired:
- Vincent Demay
- jdk-1.5-parent/push-parent-jdk-1.5
- jdk-1.6-parent/push-parent-jdk-1.6
- jdk-1.5-parent/push-parent-jdk-1.5
- jdk-1.6-parent/push-parent-jdk-1.6