|
Hi – I have added the ability to dynamically define pages at
runtime. The mechanism for loading
the page at runtime is the responsibility of your application’s engine
class. To make this work, I had to change
three files in Tapestry. IEngine.java - added new
method to getPageSpecification based on name. /** * get
specification for page based on its name * Note: returns
null if not found * @return page
specification */ public PageSpecification getPageSpecification(String name); AbstractEngine.java –
added definition for getPageSpecification. This method just looks up the definition
based on the static definitions in the application file. public PageSpecification getPageSpecification(String name) { return getSpecification().getPageSpecification(name); } PageSource.java –
changed the getPage method is use
the engine’s getPageSpecification method. Previously, would get the application’s
specification from the engine. With
the application specification object, would get the page’s specification. public IPage getPage(IEngine engine, String pageName, IMonitor monitor) throws PageLoaderException { Object key = buildKey(engine,
pageName); IPage result = (IPage) pool.retrieve(key); if (result == null) {
if (monitor != null)
monitor.pageCreateBegin(pageName);
// previous code
// PageSpecification specification = engine.getSpecification().getPageSpecification(pageName);
PageSpecification specification = engine.getPageSpecification(pageName);
… } } Finally, your application must decide how to dynamically
load a page based on its. You must
override the getPageSpecification method in your
engine’s class. For my case,
the name of my dynamic page is the path to its specification file. Later, I will change this code to look
up the specification from the database. public class StudyServerEngine extends SimpleEngine { ,,, public PageSpecification getPageSpecification(String name) { PageSpecification result = super.getPageSpecification(name); // no
definition, so lookup the page based on the name, which is the location of the
page’s jwc file. // This is simplified and does not handle errors yet or the
database lookup. if (result == null) {
// parse the jwc file
PageSpecification spec = _parser.getFactory().createPageSpecification(name);
// cache the results so that future references to the page do not
require parsing the jwc file.
getSpecification().setPageSpecification(name,
spec); } return result; } /** * had to construct my
own Specification parser because could figure out a way to get a reference * to the servlet’s parser.. */ private static final SpecificationParser
_parser = new SpecificationParser(); … } Howard – I would like to contribute this to Tapestry
if you think that this change makes sense. Thanks… Dorothy |
