Home  |  luxor-xul.sourceforge.net  |  Contact us
Calculator NG
Custom tags
  SourceForge.net Logo
Contact us

JBeantable Xul Luxor Custom Tag

By Denis (cardondenis at yahoo.com)
All comments appreciated !

This is an early alpha release of the jBeanTable custom tag. If you have not already looked at the luxor plugin package (named petra), you may do it now. It will help for undestanding the custom tag inner code.
If you don't care about writing your own plugin but want to give the jbeantable a try, you may just read what is following. Any comments/suggestions are greatly appreciated.

Note : If you have gone through web app development you may think of Luxor Xul tag as Jsp taglibs.

Note 2 : By the way, if you haven't done so, subscribe to that mailing list here : http://luxor-xul.sourceforge.net/mailinglists.html  since I won't answer questions mailed directly to me (except for comments on this document).

Note 3 : The luxor-b7 jar file has been lightly modified (bug corrected in upcoming b8). Stick to it if you want to this example to work.

Quick start

  • set up a 1.4 jvm (1.3 jvm won't work)
  • set up jakarta ant build tool (http://jakarta.apache.org/ant)
  • in PROJECT_HOME directory, type : ant
  • in PROJECT_HOME directory, type : run.bat path_to_the_project_root_dir 

the "path_to_the_project_root_dir" refers to the path of the directory where is located the run.bat file, that is to say, the home of the project (sorry, no .sh for the moment)

You should now have this swing window poping out :

  • Type the last name / first name / age and press "add". Repeat that a few time.
  • Select a few lines and click on the "view selected items" button, and look on the stdout.
  • Select one item and click on the remove item

That's all folks! Well, it is probably not the first time you have seen a JTable working, so the interesting part is the luxor stuff explained below.

So, how does it works?

Take a look a the ./src directory. Everything is located in there. It will be easier for you to understand this example if you have already been playing with Luxor-Xul (you may take a look at the "calculator" tutorial).

The demo.jbeantable.Tool class contains the main method and invokes the demo.jbeantable.AppFrame class

AppFrame is the application JFrame. It loads the xul stuff and create a com.tranquilit.formation.TrainingForm object.

The JBeantable custom tag code is located in the com.tranquilit.luxor.jbeantable package.

The ./demo/jbeantable/config/moretags.xul file

This file contains the definition for the extra-tags <jbeantable/> and <jcolumn/>. This is a kind of "taglib" file.

<tagdef name="jtable" class="com.tranquilit.luxor.jbeantable.JBeanTableDef" processbody="true"/>
<tagdef name="jcolumn" class="com.tranquilit.luxor.jbeantable.JBeanColumnDef" />

The ./demo/jbeantable/startup/layout.xul file

 <vbox id="root">
<tr><td><label value="Last Name"/></td><td> <textbox id="lastName"/> </td></tr>
<tr><td><label value="First Name"/></td><td> <textbox id="firstName"/> </td></tr>
<tr><td><label value="Age"/></td><td> <textbox id="age"/> </td></tr>

<button id="add" label="Add" command="add"/>
<button id="view" label="View selected items on stdout" command="view"/>
<button id="remove" label="Remove item" command="remove"/> <hbox> <jtable id="trainee_list"> <jcolumn title="Last Name" property="lastName"/> <jcolumn title="First Name" property="firstName"/> <jcolumn title="Age" property="age"/> </jtable> </hbox> </vbox> </xul>

The <jtable> element has an id attribute in order to be able to register this component within XulForm.

The com.tranquilit.luxor.jbeantable.TrainingForm class

This class is a standard XulForm class. The JBeanTable custom tag is referenced as a XulInput as a standard Luxor widget, so you can invoke the getJComponent() method to access the underlying Swing component.

In our case, the underlying component is a com.tranquilit.luxor.jbeantable.JBeanTable instance. Revelant methods are :

  • public List getSelectedItem();
  • public void addItem(Object o);
  • public boolean removeItem(Object o);

The "property" attribute define in the <jcolumn/> tag of the xul file (just take a look above) should be a javabean property of the bean you are adding in the jbeantable. For instance <jcolumn title="Last Name" property="lastName"/> means that there should be a public String getLastName() method in the bean you are adding to the table.


package com.tranquilit.formation;

import java.util.Iterator;
import java.util.List;

import luxor.XulAction;
import luxor.XulForm;
import luxor.XulInput;

import com.tranquilit.luxor.jbeantable.JBeanTable;

public class TrainingForm extends XulForm {
	XulInput _display;
	JBeanTable jcp = null;
	XulInput firstName;
	XulInput lastName;
	XulInput age;
	XulInput list = null;
	public TrainingForm() {

	public void init() {

		XulAction addButton = new XulAction("add") {

			public void execute() {
				Person person = new Person();
				try {
				} catch (Exception e) {
		XulAction view = new XulAction("view"){
			public void execute(){
				List selected = jcp.getSelectedItem();
				Iterator iterator = selected.iterator();
					Person person = (Person)iterator.next();
					 person.getFirstName() + " " + 
					 person.getLastName()+ " " +
		XulAction remove = new XulAction("remove"){
			public void execute(){
				List list = jcp.getSelectedItem();	

					Object o = list.get(0);
					}catch(Exception e){
		firstName = new XulInput(this, "firstName");
		lastName = new XulInput(this, "lastName");
		age = new XulInput(this, "age");
		list = new XulInput(this, "trainee_list");

	public void postInit() {
		jcp = (JBeanTable) list.getJComponent();

That's all for today

Well, this Jtable is quite basic, but I'll enhanced it in the very near future (set up column width, data type for each column, make cells editable, set editor / renderer, etc.). As usual, comments/suggestions are welcome.

   luxor-contrib.sourceforge.net  |    luxor-xul.sourceforge.net