tapestry-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Colin Sampaleanu <colin...@exis.com>
Subject Any way to get ServletContext at time 'property-specifications' are processed?
Date Mon, 18 Aug 2003 12:24:14 GMT
(sorry, I accidentally sent this to tapestry-dev instead of 
tapestry-user. question still stands)

Can anybody think of a way to the get ServletContext at the time that a 
page's <property-specification> elements are processed?

In the property-specification, I need to have an OGNL expression which 
calls a static member of a class, and feeds it the ServletContext, to 
get back a bean reference in return. Now I tried this for the expression:
   
@com.interface21.web.context.support.WebApplicationContextUtils@getWebApplicationContext(requestCycle.requestContext.applicationServlet.servletContext)

but unfortunately it doesn't work, since at the time 
property-specifications are processed, requestCycle's requestContext 
field is still null.

What I have done instead is overriden the Engine class, and stuck a 
reference to what I need in a global object, as follows:

 public static final String APPLICATION_CONTEXT_KEY = "appContext";
 protected void setupForRequest(RequestContext context) {
   super.setupForRequest(context);
  
   // insert ApplicationContext in global, if not there
   Map global = (Map) getGlobal();
   ApplicationContext ac = (ApplicationContext) 
global.get(APPLICATION_CONTEXT_KEY);
   if (ac == null) {
     ac = 
WebApplicationContextUtils.getWebApplicationContext(context.getServlet().getServletContext());
     global.put(APPLICATION_CONTEXT_KEY, ac);
   }
 }

and then in the property specification I use an OGNL expression like:

   global.appContext.getBean("myMapper")

This works, but what I don't like about this approach is that I have to 
have a custom Engine class, and have to use the Global. I guess it's not 
that big a deal, but I would still like to know if anybody can think of 
a way to get the ServletContext through OGNL at that time...

Regards,

Colin







---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org




Mime
View raw message