pp108 : Eventservice

Eventservice

Used to subscribe or publish events to the event service of Process Platform Ajax Toolkit.

Syntax

HTML

<div cordysType="wcp.library.util.EventService" id = eventserviceID> ... </div>

where, eventserviceID is the unique identifier of the component.

The eventservice is used to get the events on a real-time basis. The events are pushed to the client as and when they occur in the associated Cordys Event Service. Any application can subscribe or publish data for any particular subject, by using this component.

To dynamically add and initialize this component, you can use the initializeHTMLElements or addType methods of the Application object.

The properties, methods and events defined for this library are as follows:

Table 1. List of Attributes

Attribute

Property

Description

automatic

automatic

Boolean that defines whether to subscribe to the subject specified automatically when the page is loaded. This subscription will happen only if the subject property is also set.

  • true: Default. Subscribes to the event service with the particular subject specified when the page is loaded.
  • false: Will not subscribe to the event service when page is loaded. An explicit subscription will happen by calling the method subscribe .

subject

subject

String that contains the subject used while subscribing or publishing.

organization

organization

String that contains the organizational context in which the event service is to be used. If this property is not set, then the current organizational context of the user is taken.

Table 2. List of Methods

Method

Description

subscribe

Subscribes to the 'subject' of the event service. While calling this method, the property subject must not be empty. It returns the value 'false' if it could not subscribe to the event service. Apart from the 'subject' parameter, we also have the option of passing the 'callbackhandler'. The 'callbackhandler' specifies the function that handles the events subscribed to. If the handler function is not passed, the default event handler 'onevent' is called. For more information on 'onevent', refer to onevent.

unsubscribe

Unsubscribes the 'subject' specified. While calling this method, the property subject should not be empty.

publish(xmlObject)

Publishes to the subject subscribed in the Event Service. xmlObject denotes the data that is published in the event service.

Table 3. List of Events

Event

Description

onevent

Fires when an event for the subscribed subject arrives.

onload

This event fires when the event service component is ready to be used by the client applications. It is recommended that client applications subscribe in this event when subscribing to the event service for the first time. Before subscribing, they should check whether window.application.event.ready is true.


Related concepts

Event Service

Related tasks

Persisting Event Service Subscriptions

Related reference

Eventservice
onevent Event