views:

184

answers:

2

i integrate a flex app in a jsf-icefaces app (in a jspx site with the ice:outputmedia-tag) and want to access the same instance of a bean from flex by remote, that jsf inject.

i already connect with blazeds to a java-bean. this bean - like all other beans - get other beans by injection of jsf, but when i access the bean by remote from flex it doesnt hold the injected beans (like localizer and accesmanager, both session scoped) and i can't connect to the jsf session (FacesContext.getCurrentInstance() is null). this is because flex create a new instance of the bean and it’s not the same current instance, that jsf inject, i think.

i can connect from flex to the database by create a new entity manager in the java bean, but that's not what i want, because it's again another entity manager...i want persist and get data over the accessmanager-bean.

i know exadel fiji and flamingo, but i couldn't work with fiji, because my jsf app include the icefaces components and then it doesn't work with richfaces which fiji needs. and flamingo work only with jboss seam and spring. is it right?

i also read about the spring-flex-integration, but the jsf application did not create with spring and i don't want to integrate spring in such a large jsf app. yesterday i read about the FlexFactory interface. this interface i have to implement in my own Factory and set it in the service-config.xml of blazeds as a factory read this. i still implement my own factory but i only get application scoped beans over the servlet context which i get over FlexContext.getServletContext().getAttribute("Bean"); and not session scoped beans...

i hope there is a chance to connect throw flex and jsf... thanks!

+1  A: 

FacesContext.getCurrentInstance() is null

This will only happen when the current request is not been passed through the FacesServlet. In other words, the request URL did not match the url-pattern of the FacesServlet. It's namely the one responsible for creating the threadlocal FacesContext instance.

But you actually don't need the FacesContext here. As JSF just runs on the top of the Servlet API, you can also go low level and make use of it to grab the session scoped managed bean. JSF stores session scoped managed beans as attribues of the HttpSession with the managed bean name as key.

Thus, if you for example have a session scoped managed bean with the managed bean name myBean and you have the HttpServletRequest at your hands, then you can also access it as follows:

MyBean myBean = (MyBean) request.getSession().getAttribute("myBean");
BalusC
thank you, this really helps!over the FlexContext i get the HttpRequest:HttpServletRequest hsr = FlexContext.getHttpRequest();this.accessManager = (AccessManager) hsr.getSession().getAttribute("accessManagerBean");i don't know why i'm not worked with it! i also used this in other context...but sometimes i'm blind after hours of work ;)thanks!
David
You're welcome.
BalusC
A: 

Dear David, Can you share a sample code for how you managed to integrate icefaces & blazeds ?

i answer your question here:http://stackoverflow.com/questions/2361546/accessing-jsf-bean-from-blazeds-client/
David