Справочник Пользователя для Red Hat Web Application Framework 6.1

Скачать
Страница из 230
Chapter 12. Presentation (Bebop) Tutorial
155
12.3. Site-Wide Master Pages
Usually the pages within the scope of a single application share a common layout. For example, all
of the pages may have the same four-panel layout: the same header, footer, and sidebar content, while
the main content of the page varies. Another way of looking at this is that the main content of each
page is enclosed in another master page.
There are two aspects to making shared-layout pages like this:
1. A declaration of page components in Java. With Bebop, the top-level
Page
object must con-
tain the components that generate the dynamic content displayed in each of the header, footer,
sidebar, and main panels as DOM fragments.
2. An XSLT stylesheet to render the page properly. The XSLT stylesheet is responsible for se-
lecting the content for each of the panels on the page, and placing them appropriately in the
output, with the right look-and-feel (color scheme, dimensions, etc.) Note that this means what-
ever DOM is generated by the page components above must allow for the XSLT stylesheet to
distinguish between the content that belongs in the header, footer, etc.
The preferred way to implement shared-layout pages like this in Bebop is to subclass
Page
. Users
of this class add components to the page as usual, but the page’s constructor and DOM-generation
methods are overloaded to pre-fill the page with the appropriate boilerplate components.
The following example is a
Page
that always contains a header, footer, and sidebar:
package com.arsdigita.bebop.demo;
import com.arsdigita.bebop.*;
import com.arsdigita.xml.*;
import com.arsdigita.dispatcher.RequestContext;
import com.arsdigita.dispatcher.DispatcherHelper;
/**
* This is a common page for a fictitious site, SockPuppet.com.
* It includes a common header, a footer, and a main "content"
* area.
We override the .generateXML method to pre-fill the page
* with the boilerplate content.
*/
public class SockPuppetPage extends Page {
private Component m_top;
private Component m_bottom;
private Component m_side;
public SockPuppetPage() {
this("");
}
public SockPuppetPage(String s) {
super("SockPuppet.com: " + s);
m_top = new SiteHeader();
m_bottom = new SiteFooter();
m_side = new SiteSide();
}
public void generateXML(PageState ps, Document doc) {
Element page = generateXML(doc);
Element layout = new Element("socksite:layout", SOCKSITE_XML_NS);
page.addContent(layout);
addContents(layout, ps);
}