| Home » Developers » OpenAjax Integration - Example #1 faq | business | developers | hosting | press | terms  
Object #1: RSS Viewer (Click the headlines!)
OpenAjaxExample
Connecting an RSS Feed to an Output Window
In this example, two independent objects interact with each other via the built-in OpenAjax Hub. The first object, an RSS viewer, registers a service and publishes a message to the hub whenever the user clicks on any of the links within the viewer. The second object, a webpage viewer, subscribes to the service and is called whenever the service publishes a message. When a message is received, the webpage viewer loads the page corresponding to the link clicked in the RSS viewer.


Click the headlines in the
RSS VIEWER to automatically
update the PAGE VIEWER
Object #2: PAGE Viewer
#TITLE#
OpenAjax-linked News Feed
KEY CONCEPTS:
  • An existing rendered RSS feed is dynamically enhanced to communicate with the OpenAjax Hub

  • Scrapplet's OpenAjax Hub integration automatically handles all of the configuration and message distribution/processing.
How To Do It:
TIP: You can use a special service instance ("xwinlib_dnd" ) of the OpenAjax hub to override the default drag and drop handler. Just include the following code in the page head and then subscribe to the service:
    top.xlib.openajax.initDragAndDrop( 1 );
PUBLISHER OBJECT:
  1. Create a RSS object

    Use the Scrapplet Feed Wizard to create a feed, or copy and paste or drag and drop a RSS url onto your Scrapplet page.


  2. Register an OpenAjax Service for the object

    Access the object's properties by right-clicking on the object's header or around its borders (Mac users control-left-click, Opera users alt-left-click), then click the ADVANCED tab and then the OpenAjax logo. Enter "news.feed" as the name of the Service Identifier in the "Published Service" area, then press OK.


  3. Configure the RSS links to use the OpenAjax Service Publisher

    In this example, no additional configuration of the Publisher Object is required since the Scrapplet RSS widget has this functionality built-in. However, because this methodology can be applied to many applications, the "built-in" code is presented and discussed below:


    In the example above, all of the links within the RSS page are replaced with comparable calls to the OpenAjax Hub. The enhanced openajax.objPublish( ) function is used to create extended msg and data objects which are then passed to the traditional openajax.publish( ) function. Note that the url is encoded and passed to the "/progress.htm" page which will display a "page loading" status bar.

    The above example also could have been implemented without using the extension functions, such as in the following code:

    <a href="javascript:OpenAjax.publish('news.feed','http://news.com?57');">News headline</a>

SUBSCRIBER OBJECT:
  1. Create a WEBPAGE object
    Use the Scrapplet Webpage Wizard to create a web viewer, or copy and paste or drag and drop a WEB url onto your Scrapplet page.


  2. Subscribe to the published OpenAjax Service

    Access the object's properties, then click the ADVANCED tab and then the OpenAjax logo. Enter "news.feed" as the name of the Service Identifier in the "Services Subscribed to" area, then press OK.


  3. Configure Message Handler

    Click the button next to where you entered the service identifier to access the subscription properties. Scroll down and select INTERNAL HANDLER and enter the code as shown below:

    Here's the code for the handler presented and discussed:

    // params: e, msg, data
    var omsg, odata;
    
    // get extended msg and data objects
    // odata always uses extended format from within the object
    omsg = xlib.openajax.getMessage( msg );
    odata = xlib.openajax.getData( data );
    if ( omsg ) {
        // if extended msg, check message type
        if ( omsg.mtype & xlib.openajax.ID_MESSAGE ) {
            // set the iframe's src to the passed in url
            odata.win.iframe( ).src = omsg.msg;
        }
    }
    else {
        // if not extended message data
        // set the iframe's src to the passed in url
        odata.win.iframe( ).src = msg;
    }
    

    In the example above, the handler is optimized for both standard and extended OpenAjax Hub communications. The extended msg and data objects consist of the following data elements:

     
    Extended MESSAGE Object:
    
      omsg.sid
      omsg.mtype
      omsg.winname
      omsg.msg
      omsg.pt
      omsg.mouseButton
      omsg.key
      omsg.keyButton
      omsg.data
      omsg.lib
    
    Extended DATA Object:
    
      odata.winname
      odata.win
      odata.opts
      odata.data