Java Reference
In-Depth Information
Download reusable_layouts/web/ads_and_menu/renderer.jsp
<s:layout-render name="/ads_and_menu/layout_decorator.jsp">
<s:layout-component name="body">
Hello, reusable layout
</s:layout-component>
</s:layout-render>
which produces a page with ads and a menu:
Header
Menu Hello, reusable layout
Ads Left
Ads Right
Footer
The thing to watch for in a layout decorator is the role of the <s:layout-
component> tag. Look at the nearest parent layout tag to determine the
role. Within <s:layout-render>, the component provides content to the
layout being rendered; within <s:layout-definition>, the component is
a placeholder for content provided by a renderer.
In layout_decorator.jsp , the <s:layout-component> tag is nested in
<s:layout-render>, so it sends content to layout.jsp . The question is this
then: how do we render the content provided by renderer.jsp for the "body"
component? A-ha—with ${body} . This is how we can both provide con-
tent to the layout and render content received from the renderer for the
same component.
Adding Components
Layout decorators are not limited to adding static content and decorat-
ing the components of the parent layout. You can also add components
to the layout decorator so that renderers can provide different content
for those new components.
Taking the previous example, say you wanted to turn the menu part
into a "menu" component so that pages can have different menus. You
cannot use the <s:layout-component> tag because it is nested within
<s:layout-render> and will send content for the "menu" component to
layout.jsp (which will cheerfully ignore it).
 
 
Search WWH ::




Custom Search