CookXml JavaScript Extension



Support This Project


stats counter


Logo Logo IntelliJ IDEA

This extension basically adds a <js> tag, which supports JavaScript in CookXml using Rhino. Objects created using XML can be referenced using their id.


To add <js> to your existing tag library, say CookSwing, add the following code:

		CookJSLib.setupTags (CookSwing.getSwingTagLibrary ());

To enable Rhino JavaScript engine running in Java Web Start, however, requires the following two flags to be set.

		JSCreator.setDisablingOptimization (true);
		JSCreator.setUsingProxyJavaAdapter (true);

As for details why these two flags are necessary, check my comment on Rhino bugzilla.

The type of the object <js> tag creates depends on the JavaScript code. JavaScript code can be inserted in two ways: inside the tag, or in another file/resource specified using "src" attribute.

	<button text="Button 1">
		<js func="addActionListener">
			var listener =
				actionPerformed: function (e)
					statusBar.setText (e.getSource ().getText () + " Pressed");

			new java.awt.event.ActionListener (listener);
	<button text="Button 2">
		<!-- calling an external Javascript code (identical to the JS code above) -->
		<js func="addActionListener" src="examples/cookjs/action.js"/>


Try the Java Web Start demo for some simple demos. The frame code was also written in JavaScript.

(c) Copyright 2004-2007 Heng Yuan. All rights reserved.

Valid XHTML 1.0! Valid CSS!