Java Reference
In-Depth Information
Component: A building block for layouts and renderers. In a layout,
add a component to indicate where to put a block of content. In a
renderer, use a component to say what goes in that block. In both
cases, use the
<s:layout-component>
tag with matching name=
attributes. 1
Attribute: You can optionally add arbitrary attributes to the <s:layout-
render> tag and place their values in the layout with the name of
the attribute within ${ } . If you have something= somevalue in the
<s:layout-render> tag, using ${something} in the layout produces
somevalue.
That's it! Everything gets done with three tags. When you look at a
JSP, you can tell right away whether it is a layout by the <s:layout-
definition> tag. You also know that a JSP is rendering a layout when
you see the <s:layout-render> tag, and the path to the layout JSP
is right there in the name= attribute. The <s:layout-component> tags
determine the layout-related content. It's all there. No need to go fishing
around in configuration files to figure out what's going on.
You can think of layouts as abstract classes. They contain code that
can be reused, and components are like abstract methods. Renderers
are concrete subclasses that implement these methods by providing
content for components.
Just like abstract classes cannot be instantiated, layouts cannot be
used on their own to produce a result. Indeed, if you forward to a
<s:layout-definition> JSP, you'll get an exception. To produce a result,
you must use a renderer—a concrete implementation.
Providing Default Content
Sometimes you might find you're using the same content for a com-
ponent in most (but not all) pages. Instead of copying and pasting the
same content in those pages, you can use that content as a default
for the component in the layout. This is like having a default imple-
mentation of a method in an abstract class, which can optionally be
overridden by a subclass. To do this, put the default content in the
1. Get in the habit of using valid Java identifiers as component names—no dashes, no
spaces. . . you get the picture. Although the name "body-content" will work in a basic layout,
it can cause errors that are difficult to track down when using the more advanced layout
techniques that we'll talk about later in the chapter. Save yourself trouble, and use either
underscores or CamelCase to separate words in the names of your layout components.
 
 
Search WWH ::




Custom Search