For what it's worth, if anyone else has this issue, the following approach
works although it'll break if Howard decides to change how he stores stuff
in the session.

        --- Pat


package servlet;

import java.io.IOException;
import java.util.Enumeration;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.tapestry.ApplicationServlet;
import org.apache.tapestry.engine.AbstractEngine;

import presentation.Visit;

import data.HibHelper;

import schedule.ScheduleReader;
import utils.Clock;
import utils.Log;

public class MyServlet extends ApplicationServlet {
        private static final long serialVersionUID = 4049633486447393072L;
        private static final ThreadLocal fCurrentSession = new
ThreadLocal();
        private static final String
ENGINE_PREFIX="org.apache.tapestry.engine";

        
        public static Visit getVisit() {
                HttpSession s = (HttpSession) fCurrentSession.get(); 
                Enumeration en = s.getAttributeNames();
                while (en.hasMoreElements()) {
                        String attrib = (String) en.nextElement();
                        Log.info(attrib);
                        if (attrib.startsWith(ENGINE_PREFIX)) {
                                AbstractEngine e = (AbstractEngine)
s.getAttribute(attrib);
                                return (Visit) e.getVisit();
                        }
                }
                return null;
        }


        protected void doService(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
                Clock c = new Clock();
                HttpSession s = request.getSession();
                fCurrentSession.set(s);         
                super.doService(request, response);
                String temp = "Total Render time = " + c;
                Log.info(temp);
                HibHelper.closeSession();
        }

}

> -----Original Message-----
> From: Paul Ferraro [mailto:[EMAIL PROTECTED]
> Sent: Saturday, May 14, 2005 7:50 PM
> To: Tapestry users
> Subject: Re: Static Access to Visit Object?
> 
> Is your interceptor set in your Hibernate Configuration object? or when
> you created your Hibernate Session?
> Ideally, you would set the interceptor when you create your session, so
> that your interceptor can be constructed using the current user.
> Something like:
> 
> Session session = sessionFactory.openSession(new
> MyInterceptor(visit.getUser()));
> 
> Paul
> 
> Patrick Casey wrote:
> 
> >
> >
> >            Does anyone have any experience with some sort of static
> >approach to getting ahold of the visit object? I have a need to get at
> >information in the visit object (the current user record in particular),
> >deep, deep, deep in the bowels of some code that doesn't have access to
> the
> >cycle object (and really can't; it's running inside a Hibernate
> >Interceptor).
> >
> >
> >
> >            If worst comes to worst, I'm thinking I may have to implement
> a
> >threadlocal method to get ahold of the session and work downstream from
> >there, but I'm not all that sure how to navigate down from a servlet or
> >session object to get ahold of the Tapestry specific visit object.
> >
> >
> >
> >            Any help would be appreciated,
> >
> >
> >
> >            --- Pat
> >
> >
> >
> >
> 
> 
> ---------------------------------------------------------------------
> 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