CookJS Tutorial

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

CookJS.setupTagLibrary (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); </js> </button> <button text="Button 2"> <!-- calling an external Javascript code (identical to the JS code above) --> <js func="addActionListener" src="examples/cookjs/action.js"/> </button>