Java Reference
In-Depth Information
we are using this layout in many pages of our application, but now we
need to add several new pages that will have ads and a menu. We want
to create a layout for this without changing the original layout because
not all pages should have the ads and the menu. You don't want to
copy and paste the original layout either, because that would give us
an unpleasant WET feeling.
2
A great way to solve this problem is to define a new layout that uses
the original
layout.jsp
as a base and adds sections on the left and right
for the ads and adds the menu on the left of the body, as shown here:
<s:layout-definition>
<table>
<tr>
<td>
Ads Left
</td>
<td>
<s:layout-render name="/ads_and_menu/layout.jsp">
<s:layout-component name="body">
<table>
<tr>
<td>
Menu
</td>
<td>
${body}
</td>
</tr>
</table>
</s:layout-component>
</s:layout-render>
</td>
<td>
Ads Right
</td>
</tr>
</table>
</s:layout-definition>
Here,
layout_decorator.jsp
is both a layout and a renderer: it is a layout
with sections for the ads, and it is a renderer of
layout.jsp
. The
"body"
component is decorated by adding a menu on the left.
Now, the only difference in
renderer.jsp
is that it renders
layout_decorator.
jsp
instead of
layout.jsp
.
2.
Write Everything Twice! Write Everything Twice! WET is the opposite of the better-
known DRY, which stands for Don't Repeat Yourself. Thomas and Hunt's The Pragmatic
detail.
Search WWH ::
Custom Search