WARNING: This blog entry was imported from my old blog on blogs.sun.com (which used different blogging software), so formatting and links may not be correct.
If you're writing a JSF component, there are a couple of things
you can do to make the component behave more nicely at design
time. (Well, there are actually a lot of things you can be doing,
and we'll document these shortly, such that your components
can have the same rich designtime behavior in Creator that for example the
standard JSF data table has.)
Anyway, some of these techniques are general beyond the Creator JSF
designtime library:
First, in your renderer, which generates HTML from the JSF component,
you can check the
Beans.isDesignTime() property. If set, the component
is being rendered during design time preview of the component,
so you can change what you render accordingly. For example,
if you have a "container" component, and it has zero children,
at runtime you probably want your container to render nothing, but
at design time you should render something to show the user
your component; for example, you can set up a particular size
for your component or render some explanatory text within the
container. This example for simplicity just sets the background color to red:
if (Beans.isDesignTime() && component.getChildCount() == 0) {
writer.writeAttribute("bgcolor", "red", null); // Ugly example
} else {
...
Another thing you can do is include images from your component library
at designtime -- these don't need to be included in the user's project
since they are just shown at design time and are therefore available
to the IDE:
if (Beans.isDesignTime() && component.getChildCount() == 0) {
// Show special design time icon
writer.startElement("img", component);
URL url = MyClass.class.getResource("myicon.png");
writer.writeURIAttribute("src", url, null);
...
Finally, I've
already mentioned how you might want to set the
default property for your component to improve the design time
handling of this component.