Well, the way I would do it would be like this:
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("
yourbeanname");
Now, I'm working in Facelets, so I'm not using JSPs at all, but if you don't
have access to a FacesContext, then I'd try something along these lines:
Assuming you have an HttpServletRequest request...
request.getSession().getAttribute("yourbeanname");
I think that would work, but you'd have to test it out to be sure, and if it
doesn't work, there's some simple way to get access to the Session, because
the session exists independently of JSF, JSP, etc.
Jeremy Sager
Data Communications Product Manager
Chesapeake System Solutions
410.356.6805 x120
[EMAIL PROTECTED]
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Thursday, January 26, 2006 4:26 PM
To: 'MyFaces Discussion'
Subject: RE: using jsf backing bean in non jsf jsp
How do I do that?
-----Original Message-----
From: Jeremy Sager [mailto:[EMAIL PROTECTED]
Sent: Thursday, January 26, 2006 1:09 PM
To: 'MyFaces Discussion'; [EMAIL PROTECTED]
Subject: RE: using jsf backing bean in non jsf jsp
Why not just get the bean right from the session attribute map?
Jeremy Sager
Data Communications Product Manager
Chesapeake System Solutions
410.356.6805 x120
[EMAIL PROTECTED]
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Thursday, January 26, 2006 2:20 PM
To: 'MyFaces Discussion'
Subject: using jsf backing bean in non jsf jsp
I have a jsf page the brings up a non jsf jsp in both an iframe and as a
popup.
I want to use the jsf backing bean (consoleHandler below) in the jsp. I
used:
<%
LifecycleFactory lFactory =
(LifecycleFactory)FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
Lifecycle lifecycle =
lFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
FacesContextFactory fcFactory =
(FacesContextFactory)FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FA
CTORY);
FacesContext facesContext =
fcFactory.getFacesContext(getServletContext(), request, response,
lifecycle);
ConsoleHandler consoleHandler =
(ConsoleHandler)facesContext.getApplication().getVariableResolver().resolveV
ariable(facesContext, "consoleHandler"); %>
This worked fine on my development machine, the same bean is used by the jsp
page, but when I uploaded it to the production server, the jsp creates a new
instance of the backing bean every time it is called (I put a println in the
bean constructor).
The code base is exactly the same. Any ideas why this would happen?
Thanks,
Lance