On 1/27/07, Danny Worm <[EMAIL PROTECTED]> wrote:

Hi,

I've added the application manager to my application. This feature is
very nice to me. But there is an question about a command-class in the
preprocess-chain. Is it possible to get the FacesContext from the
web-application or an similar way to get the managed-beans from the
factory?


As long as you are executing inside a JSF request (i.e. a request mapped to
FacesServlet), you can use a convenient static method to get the
FacesContext for the current instance:

   FacesContext context = FacesContext.getCurrentInstance();

However, the preprocess chain is executed in a Servlet Filter, before the
JSF machinery has had a chance to create the FacesContext.  Therefore,
you'll want to access the underlying servlet API objects directly.  The
simplest way to do that is to cast the Context object passed in to your
command to a ShaleWebContext, which gives you accessors for all the servlet
API objects.


I want to rebind hibernate to the session.


To bind the hibernate session to a session attribute named "foo", you'd do
something like:

   Session hibernate =  ... create a hibernate session ...;
   ShaleWebContext swc = (ShaleWebContext) context;
   HttpSession session = (HttpSession) swc.getSession();
   session.setAttribute("foo", hibernate);

thanks
kind regards
DaWorm



Craig

Reply via email to