Featured Whitepapers
Newsletter sign-up
View all newsletters

Sign up for our technology specific newsletters.

Enterprise Java
Email Address:

The trick to controlling bean customization

Make your beans easy to customize using the BeanInfo interface and the Introspector class

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
We want our beans to be easy to use, not just for users, but also (and especially) for application developers customizing our beans by changing their properties.

In the September issue of JavaWorld, in my article "Double Shot, Half Decaf, Skinny Latte: Customize your Java," we looked at how to make JavaBeans customizable. A simple naming scheme provides a minimal mechanism for giving an Integrated Development Environment (IDE) or other bean container object -- like the BeanBox, for example -- a way to let a user customize a bean. (For more information on the BeanBox, see my JavaWorld article "The BeanBox: Sun's JavaBeans test container.") When a bean needs to be customized, the IDE analyzes the bean's class and creates a quick-and-dirty dialog box containing little edit widgets (called property editors) for each property, which it then pops up on the screen. Controlling, replacing, and extending what gets popped up is what this article is all about.

This month, we'll go over the conceptual groundwork for understanding the different customization facilities in JavaBeans. You'll learn about the various customization levels and the classes used to implement them. Then, we'll look at an example of one of the simpler forms of customization by using the BeanInfo interface, which tells the container more about the bean than it could figure out on its own. We'll also write a very simple custom property editor (which lets you edit properties any way you like) and install it in the BeanBox. Along the way, we'll touch on the Introspector class -- the JavaBeans class used by IDEs and other bean containers to analyze class files.

Next month, we'll concentrate on code, writing and using a Customizer, registering property editors, and having a look at controlling bean visibility.

Note: In this article, I'll use the term IDE to mean "any container that cares about what's inside a bean." This is not, of course, limited to IDEs: Beans-aware browsers, bean testers like the BeanBox, information "buses," and the like all may need to know what's inside a bean. I use "IDE" because it's only three letters, and because it's one of the places where customization functionality is most commonly used.

Levels of customization

As beans become more complex, the number of properties (and, therefore, the number of getter and setter methods) begins to explode. More and more properties appear on the dialogs, and soon the dialogs we use to customize beans are oversized, awkward to use, and confusing.

It may not be immediately clear to the user of the bean what all the different properties mean or how they relate to one another. Some properties, particularly indexed properties, may have no reasonable default screen representation. Others may simply be more "friendly" if edited graphically.

The JavaBeans Specification and the java.beans package come to the rescue again, with a flexible, open, and extensible set of conventions, classes, and interfaces. These give you, the bean developer, control over what appears on the screen when someone adds your bean to their application and then wants to customize it.

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comment
Login
Forgot your account info?
Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources