More action with Struts 2
In a recent review of Struts 2 in Action, JW Blogger Oleg Mikheev notes that Struts 2 is "just a collection of extensions built upon WebWork, which is ultimately the right thing to learn before starting a Struts 2 project." While Struts 2 has some architectural flaws, Oleg calls WebWork well-designed, well-tested, and reliable. What are your experiences using Struts 2 and WebWork?

Also see "Hello World the WebWork way," a JavaWorld excerpt from WebWork in Action, by Patrick Lightbody and Jason Carreira.

Newsletter sign-up

Sign up for our technology specific newsletters.

Enterprise Java
View all newsletters

Email Address:

Bean Markup Language, Part 2

Create event-driven applications with BML

Any system made up of components needs a way to connect those components to one another. In an automobile, that framework is the auto frame (itself a component), to which other components are attached. In electronics, it's the chassis, the circuit board, or the substrate, depending on what level of component-use you mean.

Last month, a reader commented that BML didn't work as well as an IDE, or integrated development environment, for creating user interfaces, and I agree. But the power of and interest in BML derives from its ability to create structures of arbitrary classes -- not just user interfaces or JavaBeans -- to build an application. More importantly, BML can define an application declaratively, usually without procedural code. This makes it much easier for (potential) builder tools to compose functionality into applications, much in the same way a dialog editor composes GUI elements into a user interface. In fact, since BML defines applications structurally rather than procedurally, it can be used to automatically generate interactive interfaces for arbitrary datastructures.

TEXTBOX: TEXTBOX_HEAD: Bean Markup Language: Read the whole series!

IBM's Bean Markup Language provides just such a software chassis for Java object instances, particularly instances of JavaBean components. As I demonstrated in August (see Part 1 of this two-part series in Resources below), you can use BML to create configured instances of JavaBeans.

This month, I'll show you how to create instances of several objects in BML and then use BML to wire these objects together. I'll also show you how to execute any method of an object from BML, extend BML to handle conversions between data types, and explore binding Java objects created in BML to a scripting language (in this case, JavaScript). Since I assume you've read the first article, let's dive right into this month's sample code.

A BML application

I'm going to extend last month's ColorFadeBean by transforming it into the interactive ColorFadeEditor.bml (click the link to see the file). I've added an AWT text field to the original ColorFadeBean, which sets the text in the ColorFadeBean, and three ColorChooser objects, which set the text color and the start and end colors for the color gradient. A picture of the ColorFadeEditor appears in Figure 1.

Figure 1. ColorFadeEditor defined entirely in BML



This application is actually a single-nested hierarchy of GUI elements, as it must be, since an XML document may have only one top-level element. You'll notice that the BML file contains no Java code. That's because BML is a language used for wiring JavaBeans together, not for creating new JavaBeans (although defining JavaBeans in BML will be a feature of an upcoming BML release). The color gradient in the ColorFadeBean, for example, is created by the bytecodes in ColorFadeBean.class, which can be considered an off-the-shelf JavaBean. BML sets the bean's exposed properties and so on, but it can't add new properties or behavior.

Resources
  • Download the source code for this article:
  • Related JavaWorld resources
  • IBM BML and XML resources
  • The three great virtues of a programmer
  • According to Larry Wall, the creator of Perl (the second-best computer language in existence), the three great virtues of a programmer are laziness, impatience, and hubris. Read a description here
    http://hiro.protagonist.net/perl/virtue.html