CookXml BeanShell Extension


 

 

Support This Project

 

stats counter

 

Logo SourceForge.net Logo IntelliJ IDEA

This extension basically adds a <bsh> tag, which supports BeanShell in CookXml. Each time this tag is used, a new instance of Interpreter is created. Objects created using XML can be referenced using their id.

Personally I am not a big fan of scripting inside XML, since excessive use of scripts instead of actual Java code is meaningless in terms of developemental efforts and performance. However, from time to time I do find myself wishing to have extra flexibilities in designing certain aspects of GUI using XML. See the demo offered below to see what I mean.

Tutorial

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

		CookBSHLib.setupTags (CookSwing.getSwingTagLibrary ());

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

	<button text="Button 1">
		<bsh func="addActionListener">
			import java.awt.event.ActionListener;

			actionPerformed( e )
			{
				statusBar.setText (e.getSource ().getText () + " Pressed");
			}

			return (ActionListener)this;
		</bsh>
	</button>
	<button text="Button 2">
		<!-- calling an external BSH code (identical to the bsh code above) -->
		<bsh func="addActionListener" src="examples/cookbsh/action.bsh"/>
	</button>

Demo

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

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

Valid XHTML 1.0! Valid CSS!