On 2/23/06, Vladimir Coutinho <[EMAIL PROTECTED]> wrote:
I need to get a reference to a the Session to read a value in a user variable.
In jsf I use:
 (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
 
Works well, but when the url is not jsf, it doesn't work. There is some way to get a reference to the session in a bean? I'm calling this bean from AJAX code.

If you are not in a faces request, then you need to go back to the tried and true mechanisms of the servlet API ... but this will require you to have access to the HttpServletRequest instance for the AJAX request, which means you will need to take that into account when defining your APIs.

A completely different approach to this problem is to make sure all your AJAX requests are actually Faces requests.  Shale's "Remoting" feature has some logic that can make that pretty easy, including a mechanism that can translate a context-relative URL like ("/dynamic/foo/bar.faces") into the evaluation of a method binding expresion "#{foo.bar}" that will produce the AJAX response.  It's not documented particularly well yet, but this code arose out of my having a similar need (although, in my case, it was more driven by the desire to be able to use managed beanas than anything else).

Craig

Reply via email to