I have a web application written in JSF2 that uses Spring. I need to create a bean that is a wrapper of JSF HTTP session and use it internally. It seems logical to me to inject the HttpSession object into that bean’s definition and to scope the bean to the session. However I could not find a way to define the injection in the context.xml file. Is it possible to do this, could it backfire and is there a better way? All I want is to have the current session inside that bean. If there is a static method to get the session (similar to HttpContext.Current.Session in ASP.NET), it will also be of good use. Thanks in advance.
Share
I’m not sure about the Spring part (I don’t use it, I use just the standard Java EE 6 API), but you can get the
HttpSessionstatically in JSF context byExternalContext#getSession()as follows:You could do that in the bean’s (post)constructor.