|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.arsdigita.bebop.PageFactory
The PageFactory
provides a framework for
instantiating instances of the Bebop Page
class in a
project- and application-independant manner.
The traditional approach to writing bebop applications is to subclass the com.arsdigita.bebop.Page, adding various components to provide navigation & layout and writing custom XSL for styling purposes.
The problem of this approach is that when multiple applications are combined to form a complete site, is it difficult to produce an integrated navigation infrastructure & uniform styling across all pages. In addition, by placing application specific functionality in a subclass of Page, the ability to reuse & embed applications within each other is hampered since Page objects cannot be nested.
The PageFactory addresses the following situations
The point of interaction for PageFactory is typically in the
application's Dispatcher class. Rather than invoking the Page
constructor (ie new Page(title)
), applications call
PageFactory.buildPage(title, "appname")
This method
will return an instance of Page with the currently configured
navigation components added.
The two compulsory arguments to the buildPage
method are the name of the application (ie, 'forum', 'cms'), and
the page title (either as a String or Label object). The
application name is used as key in both the enterprise.init file
configuration & the XSL templates. There is optionally a third
string id
parameter which provides a unique identifier
for the page within the application. If the page class is a
subclass of ApplicationPage this will be used to set the XML
id
attribute.
Consider the following example (based loosely on the Simple Survey application):
package com.arsdigita.simplesurvey.dispatcher; import com.arsdigita.simplesurvey.ui.IndexPanel; import com.arsdigita.simplesurvey.ui.AdminPanel; import com.arsdigita.simplesurvey.ui.SurveySelectionModel; import com.arsdigita.bebop.BigDecimalParameter; import com.arsdigita.bebop.BebopMapDispatcher; public class Dispatcher extends BebopMapDispatcher { public Dispatcher() { Page index = buildIndexPage(); Page admin = buildAdminPage(); addPage("index.jsp",index); addPage("", index); addPage("admin/index.jsp",index); addPage("admin", index); } private Page buildIndexPage() { SurveySelectionModel survey = new SurveySelectionModel(new BigDecimalParameter("survey")); Page page = PageFactory.buildPage("simplesurvey", "Simple Survey", "index"); page.add(IndexPanel(survey)); page.addGlobalStateParam(survey.getStateParameter()); page.lock(); return page; } private Page buildAdminPage() { SurveySelectionModel survey = new SurveySelectionModel(new BigDecimalParameter("survey")); Page page = PageFactory.buildPage("simplesurvey", "Simple Survey Administration", "admin"); page.add(AdminPanel(survey)); page.addGlobalStateParam(survey.getStateParameter()); page.lock(); return page; } }
The process of updating existing applications to make use of the PageFactory varies according to the complexity of the application in question.
In the simplest case where an application has not subclassed the
Page class, then it is just a case of replacing calls to new
Page(title)
with PageFactory.buildPage("appname",
title)
.
When an application has subclassed Page, then the initial
approach is to change the subclass in question so that it derives
from SimpleContainer instead of Page. Any calls to the
addGlobalStateParam
or addRequestListener
methods can be moved from the constructor into the
register
method where there will be direct access to
the Page
object.
The com.arsdigita.bebop.base_page
system property
may be used to specify the full name of a subclass of Page which
provides the constructor signature detailed in the
setPageClass
method. If omitted it defaults to
BasePage
.
The com.arsdigita.ui
package provides an
alternative subclass called SimplePage
which supports
specification.
BasePage
Constructor Summary | |
PageFactory()
|
Method Summary | |
static Page |
buildPage(String application,
Label title)
Instantiates a new instance of the Page class. |
static Page |
buildPage(String application,
Label title,
String id)
Instantiates a new instance of the Page class, with the optional unique page id string. |
static Page |
buildPage(String application,
String title)
Instantiates a new instance of the Page class. |
static Page |
buildPage(String application,
String title,
String id)
Instantiates a new instance of the Page class, with the optional unique page id string. |
static void |
setPageClass(Class page)
Sets the page class to instantiate. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public PageFactory()
Method Detail |
public static void setPageClass(Class page)
page
- the page classpublic static Page buildPage(String application, String title)
application
- the application nametitle
- the page title
public static Page buildPage(String application, String title, String id)
application
- the application nametitle
- the page titleid
- the page id within the application
public static Page buildPage(String application, Label title)
application
- the application nametitle
- the label for the page title
public static Page buildPage(String application, Label title, String id)
application
- the application nametitle
- the label for the page titleid
- the page id within the application
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |