interesting issue with Controller and FacesContext

Hi,

 

Does anyone know why when i try to get FacesContext.getCurrentInstance() inside Controller implemenation function (handleRequest),

the current instance is null?

 

Thanks,

Oded.

 

 

Comments

Can you put some more information?
Like code example of what are you exactly trying to do?
Environment details, what kind of thirdparty are you using?

It might be life cycle issue or thirdparty issue.

we are having a jsf / facelets and acegi spring security..
just a regular controller defined in the web.xml
<servlet-mapping>
	<servlet-name>ssoLogin</servlet-name>
	<url-pattern>/ssoLogin/*</url-pattern>
</servlet-mapping>
<servlet>
	<servlet-name>ssoLogin</servlet-name>
	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
	<load-on-startup>2</load-on-startup>
</servlet>
and defined in ssoLogin-servlet.xml
<bean name="/login" class="com.XXX.XXX.XXX.SSOController" />
and as I mentioned I'm trying to get the current instance which is null --> FacesContext.getCurrentInstance().getExternalContext().getContext()
Cheers.

I am not a Spring user or advocate (I am using Seam) but I think your request isn't in a JSF context. It would be beneficial to know why you need the FacesContext in your bean/controller and what you are using it for.

Any way, these might be helpful:

http://cagataycivici.wordpress.com/2005/12/25/integrating_jsf_and_spring/

http://blogs.steeplesoft.com/facesutil-a-missing-yet-important-piece/

http://www.thoughtsabout.net/blog/archives/000033.html

Yeah it looks like you need the third link Shlomo referenced.

It is !

I need to initial a jsf bean from that spring controller and then to navigate.
yes, it makes sense, this controller is a Spring MVC and i want it to work on a Spring Web Flow, 
in other words, this controller is not going through the jsf-faces servlet?
if so, how can I make a spring controller work with jsf ?

yes, the third link really might help :)
"because a filter is running before a Faces servlet the context hasn't been set up for this request"
Thanks, guys.

it is working, i checked it . with the same environment like yours off course :)

yes it is working (indeed a neat work-around :) ), 
but , a better way dealling with this issue would be using @controller instead of implementing controller(MVC),
having jsf/spring faces abilities and mvc together. 
in this way the controller is in the same scope (@Autowired can be used and faces context is alive...)