building many user interfaces, it may help to build a sample and a template
that can be used for these types of user interfaces.
Antipattern: Compound JSPs
The basket is swinging wildly. Dee delicately brushes against a bush to dampen the
swinging, and then slams us down. The bone-jarring impact throws Dee forward
into the tanks. Ribs crack. With Dee's instructions, I am able to pull a rope that
lowers the balloon's top panel, letting the hot air escape and bringing us finally to
a standstill. We cannot believe that the riskiness of the operation was so well hid-
den from us at higher altitudes. We lick our wounds and wait for the ground crew
to come and help pick up the pieces.
The Monolithic JSP is not the only JSP antipattern you could encounter. In
the next antipattern, we have a model-view-controller-compliant architecture
that falls short in other ways. On my fateful balloon trip, the calm air at higher
altitudes lured us into a false sense of security. Only when we closely examined
conditions at lower altitudes did we fully appreciate our danger. Confidence in
the Triangle design pattern can also lure us into complacency. Choosing a
higher level design does not mean you no longer have to worry about prop-
erly implementing the architecture. Closer to the ground-level details, we
must also be alert to danger. In this antipattern, we will examine one such
detail: should we force decisions into the JSP or the controller? Consider a case
where the results of a command execution will determine which page, or page
fragment, is returned to the user. The logical place for such a check might
seem to be the JSP , as in figure 4.1.
Should we combine multiple JSPs?
This antipattern is known as the Compound JSP , in which a single JSP is used
to return one of many result sets, leading to too much logic in our JSP . Severe
error conditions and routine errors, such as not-found errors and validation-
failed conditions, are common places to find this antipattern. Table 4.2 shows
the problems with the Compound JSP approach.
In general, although Compound JSP s may be slightly easier to create, they
make maintenance, reuse, design through common tools, and project
management much more difficult. As antipatterns go, this one has relatively
minor side effects. Still, the ease of refactoring and the ease of doing it right
the first time make this an attractive refactoring target.