You aren't missing anything. Upgrade to the latest Beta-9 build, the ServletContext wasn't available originally (but was "requested" that it be added). Then just inject it as a service, like you would a WebRequest (it might be available via infrastructure:, but I haven't looked).

----- Original Message ----- From: "Greg Ward" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Friday, September 30, 2005 3:51 PM
Subject: Tapestry 4 migration: how to initialize a Global object?


I'm trying to migrate a Tapestry 3 app to Tapestry 4.  My first
stumbling block is initializing (not creating) my Global object.  Under
Tapestry 3, our app initializes itself like this:

 * our ServletContextListener stuffs various interesting objects into
   the ServletContext (e.g. a Configuration object, the log filename,
   application version string -- stuff that should be setup in the
   ServletContextListener)

 * we provide a custom Engine class that overrides createGlobal();
   it's happy to let Tapestry create the Global object
   with "new Global()", but that does not result in a usable object --
   we have to copy stuff from the ServletContext into the Global object:

   protected Object createGlobal( RequestContext requestContext )
   {
     Global global = (Global) super.createGlobal( context );
ServletContext context = requestContext.getServlet().getServletContext();
     global.init(
(Configuration) context.getAttribute( Constants.CONFIGURATION_ATTR ),
       ContextListener.getNotifier( context ),
       (String) context.getAttribute( Constants.PROJECT_NAME_ATTR ),
       (String) context.getAttribute( Constants.PROJECT_VERSION_ATTR ),
       (String) context.getAttribute( Constants.LOG_BASENAME_ATTR ) );
     return global;
   }

I'm absolutely clueless how to do this in Tapestry 4.  I've gotten as
far as creating hivemodule.xml and asking HiveMind to kindly instantiate
one of our Global objects rather than a HashMap ... but then how the
heck do I initialize it?  I can't do it from the ServletContextListener,
because that runs before Tapestry/HiveMind ever enter the picture.  But
everywhere I try to hook in to Tapestry, I can't see how to get my hands
on a ServletContext -- everything's hidden behind WebRequest, and
there's no apparent way to get from a WebRequest to a ServletContext.
Argh!  What am I missing?

Thanks --

       Greg

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to