Prototype Integration

Table of Contents

Prototype JavaScript Framework Integration

Plugin Integration

An extension library for Prototype clients of Java Web applications is provided with the JavaScript file prototype.icepush.js.

Initialization and Page Inclusion

  1. Include icepush.jar in your Java web application
  2. Declare the ICEpush javascript code in the head region of any HTML page requiring push in your application
    <script type="text/javascript" src="code.icepush"></script>
    
  3. Declare the Prototype library and ICEpush Prototype integration Javascript file after the ICEpush JavaScript
    <script src="./javascript/prototype.icepush.js" type="text/javascript"></script>
    <script src="./javascript/prototype.js" type="text/javascript"></script>
    

Prototype ICEpush Plugin API

function Push.listenToGroup(groupName, callback);

This function will add the client page to a push group, and register the provided callback listener with the ICEpush bridge. The callback listener will be called when a push notification occurs for the specified group.

Arguments
  • groupName: The name of the ICEpush group being joined.
  • callback: The listener function that will be called when the joined group is notified of an event.
Example

Here the client registers itself with an ICEpush group called 'time', and provides an anonymous callback listener function. The group 'time' does not have to be previously declared on the server or client, and will be created by the ICEpush bridge when this registration occurs. When any notifications for the group 'time' occur, the ICEpush bridge will call this function, and the function will create a Prototype Ajax.Updater object to update the 'timeElem' element. These push events can be triggered on the client through a call to ice.push.notify(groupName); or from the server-side with the Java API.

Push.listenToGroup("time",
                   function(){ new Ajax.Updater('timeElem', './time', { method: 'get'});});

function Push.stopListeningToGroup(groupName, callback);

This function will remove the client page from a joined group, unregistering the client from a previously registered group.

Arguments
  • groupName: The name of the ICEpush group.
  • callback: The listener function previously registered. If not provided, the function will remove all callback listeners from the ICEpush group (as there may be more than once listener attached to a group).
Example

Here clicking the button will remove the client page from the 'time' group, removing all callbacks registered for that group.

<input type="button" value="Stop Clock" onclick="Push.stopListeningToGroup('groups');" />

If we had multiple different callback functions registered to the time group we could selectively remove individual functions this way:
<input type="button" value="Stop Clock"
       onclick="Push.stopListeningToGroup('groups', myCallbackListener);" />

function (Prototype selector).loadPushUpdates(groupName, url, insertionPoint);

The function will register the client page with an ICEPush group, and automatically call the provided url when an ICEpush event occurs for the registered group. When a push event occurs, a HTTP GET request will be made for the provided url, and the HTML response will be loaded into all selected elements from the prototype selector.

Arguments
  • groupName: The name of the ICEpush group being joined.
  • url: The url that will be called on a push event for the group.
  • insertionPoint: The insertion point for the updated content ('top','bottom','before','after').
Example

This code starts with the prototype selector $$('div.groups') which selects the two divs above the script. The .loadPushUpdates('groups','./groups'); registers the client page with the ICEpush group 'groups'. When an ICEpush notification occurs for the group 'groups', the url './groups' will be called with an HTTP GET request, and the resulting response will be placed inside both selected div elements.

<div class="groups"></div>
<div class="groups"></div>
<script type="text/javascript">$$('div.groups').loadPushUpdates("groups","./groups");</script>

class AjaxPush.Updater(container, pushGroup, url, options);

The class will register the client page with an ICEPush group, and automatically call the provided url when an ICEpush event occurs for the registered group. When a push event occurs, a prototype Ajax.Updater will be created with the container, url and options.

Arguments
  • container: The HTML element to the updated
  • pushGroup: The name of the ICEpush group being joined.
  • url: The url that will be called on a push event for the group.
  • options: Optional parameters passed to the Prototype Ajax.Updater class.
Example

This code will register the page with the push group named 'groups'. When a push notification event occurs for the group 'groups', a Prototype Ajax.Updater class will be created that calls the url './groups', with an HTTP GET request and places the response into the HTML element with the id 'groupsElem'.

<script type="text/javascript">
new AjaxPush.Updater('groupsElem', 'groups','./groups', { method: 'get'});
</script>
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

© Copyright 2017 ICEsoft Technologies Canada Corp.