OpenWGA 7.7 - JavaScript reference

WGA.event
Method :

WGA.event.addListener(pKey, eventName, f)

On object WGA.event
Usage Listen for portlet events of the given name
Description

This method registers a JavaScript function which will get called when the portlet event is fired. This function is called with an "event object" as parameter.

It is especially suited to catch portlet events that were already fired on the client side via WGA.event.fireEvent().

The event object has the following properties:

  • name: the name of the event
  • source: the source of the event, normally the portlet key of the portlet that fired it
  • params: a JavaScript object with the event parameters sent by WGA.event.fireEvent()

It is neccessary to assign the listener to a WebTML portlet of the current page. The registration code should be in the output code of this portlet, so the registration runs every time the portlet gets reloaded. The WGA portlet registry will register the event for that portlet and will remove it from the registry once this portlet gets reloaded or unloaded.

Parameters

pKey (String):
The key of the portlet which the event script belongs to

eventName (String):
The Name of the event

f (JavaScript Function):
function to be called when the event fires

Writable False
Return value none
Examples

Script code adding a listener function which calls an WebTML AJAX action when an event fires.

<tml:form id="myform" source="portlet">

  <tml:input type="hidden" name="key"/>

  <script>

WGA.event.addListener(

"<tml:script expression="portlet.portletkey"/>"

"key_selected", 

function(e){

document.forms.myform.key.value=e.params.key;

WGA.ajax.callAction("<tml:action ref="$store"/>")

});

  </script>

</tml:form>