Implementing the event mechanism

Do the following steps to implement the event mechanism:

  1. Define the event handler in widget Java™ script:
    this.handler1=function(){
    		alert("handler!!!");
    		BTTUtil.Servicelist.addListener('1.2', 'onclick', function(){
    			if(!BTTUtil.Servicelist.isCategoryNode('2.4')) {
    				var tabId = BTTUtil.Workarea.addTab();
    				var columnId= BTTUtil.Workarea.addColumn(tabId);
    		        var rowId= BTTUtil.Workarea.addService(columnId,0, 
    {title : 'testADDROW007', draggable : '1'}, {id : "simpleHTMLWgt", attribute : {url:"http://www.ibm.com"}} );
    				BTTUtil.Workarea.showTab(tabId);
    			}
    		});
    		BTTUtil.Servicelist.addListener('1.3', 'beforeonclick', function(){
    			if(!BTTUtil.Servicelist.isCategoryNode('2.4')) {
    				alert("beforeonclick");
    			}
    		});	
    	}
  2. Declare the event in widget definition XML file:
    <iw:itemSet id="attributes" private="true">
            <iw:item id="url"  value="http://www.ibm.com"/>
            <iw:item id="height" value="300"/>
        </iw:itemSet>
        <iw:event id="event1" onEvent="handler1"/>
        <iw:content mode="view">
  3. Invoke the event:
    BTTMain.Portal.widgetRunTime.eventRepository.fireEvent('event1');
    BTT Web 2.0 especially provides multiple parameters for you to fire event:
    Table 1. Fire event
    API Input Output
    BTTMain.Portal.widgetRunTime.eventRepository.fireEvent P1,P2, P3,…Pn P1 is the event id, P2,…Pn are the input parameter of handler .
    The following is an example showing how to fire the event:
    Table 2. Example showing how to fire event
    BTTMain.Portal.widgetRunTime.eventRepository.fireEvent('event1','2.4','this is event for 2.4')
    The following example shows the handler that is called by the event.
    Table 3. Example showing the handler
    this.handler1=function(serviceid, message){
    		
    		BTTUtil.Servicelist.addListener(serviceid, 'onclick', function(){
    			if(!BTTUtil.Servicelist.isCategoryNode(serviceid)) {
    				alert(message);
    				var tabId = BTTUtil.Workarea.addTab();
    				var columnId= BTTUtil.Workarea.addColumn(tabId);
    		        var rowId= BTTUtil.Workarea.addService(columnId,0, 
             {title : message, draggable : '1'}, 
             {id : "simpleHTMLWgt", attribute : {url:"http://www.goolge.com"}} );
    				BTTUtil.Workarea.showTab(tabId);
    			}
    		});

    The input for serviceid is 2.4 and the input for message is this is event for 2.4 as shown in Table 2.