RSS Viewer - JavaFX to JavaScript Communication

By Rakesh Menon, December 8, 2008

This sample demonstrates how to implement JavaFX to JavaScript communication using LiveConnect Support.
The RSS feed specified in the textfield is parsed using JavaFX WebService APIs. The data is then rendered on HTML. User can specify a new RSS feed URL and click on RSS button to load the feed.

Understanding the Code

RSS feed specified in textfield is parsed by JavaFX WebService parser.
Its then set back to HTML by invoking updateChannelData(channelData) JavaScript method.
This method updates the content of HTML page.

Source Code
    
    function updateChannelData(channelData) {
        document.getElementById("ChannelData").innerHTML = channelData;
    }
    
    <div id="ChannelData" style="text-align: center;"></div>
    

Next and previous items in channel is set by invoking updateChannelData(channelData) with new set of data.

Below code shows how to invoke JavaScript method from JavaFX.

Source Code
    
    // Get the Applet instance
    var applet: Applet = FX.getArgument("javafx.applet") as Applet;
    
    // Get JSObject instance
    var window = netscape.javascript.JSObject.getWindow(applet);
    
    // Invoke JSObject.call function passing the table data as argument
    window.call("updateChannelData", ["{tableData}"]);
    

References