com.arsdigita.bebop
Class PageFactory

java.lang.Object
  extended bycom.arsdigita.bebop.PageFactory

public class PageFactory
extends Object

The PageFactory provides a framework for instantiating instances of the Bebop Page class in a project- and application-independant manner.

History

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.

Use Case

The PageFactory addresses the following situations

  1. It is common for all pages on a site to have a particular structure. ie, header, footer, left sidebar & main content * area.
  2. It is desirable to customize page structure without making code changes to individual applications.

Example Usage

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;
   }

 }
 

Updating existing applications

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.

Configuring the page factory

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.

See Also:
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

PageFactory

public PageFactory()
Method Detail

setPageClass

public static void setPageClass(Class page)
Sets the page class to instantiate. The class should have a public constructor that takes three arguments. The first 'String' argument is the name of the application, the second 'Label' is the page title, and the third (optionally null) argument is a page id (unique string with this application). The common case is to inherit from ApplicationPage and pass these three arguments straight through to its constructor.

Parameters:
page - the page class

buildPage

public static Page buildPage(String application,
                             String title)
Instantiates a new instance of the Page class.

Parameters:
application - the application name
title - the page title
Returns:
a subclass of com.arsdigita.bebop.Page

buildPage

public static Page buildPage(String application,
                             String title,
                             String id)
Instantiates a new instance of the Page class, with the optional unique page id string.

Parameters:
application - the application name
title - the page title
id - the page id within the application
Returns:
a subclass of com.arsdigita.bebop.Page

buildPage

public static Page buildPage(String application,
                             Label title)
Instantiates a new instance of the Page class.

Parameters:
application - the application name
title - the label for the page title
Returns:
a subclass of com.arsdigita.bebop.Page

buildPage

public static Page buildPage(String application,
                             Label title,
                             String id)
Instantiates a new instance of the Page class, with the optional unique page id string.

Parameters:
application - the application name
title - the label for the page title
id - the page id within the application
Returns:
a subclass of com.arsdigita.bebop.Page


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 21 2004:2337 UTC