flex 和 jsf 访问同一个 bean 实例

发布于 2024-08-18 21:36:05 字数 1068 浏览 6 评论 0原文

我将一个flex应用程序集成到jsf-icefaces应用程序中(在带有ice:outputmedia-标签的jspx站点中),并希望通过远程访问来自flex的同一个bean实例,即jsf注入。

我已经用 blazes 连接到 java-bean。这个bean - 像所有其他bean一样 - 通过注入jsf获取其他bean,但是当我从flex远程访问bean时,它不保存注入的bean(如localizer和accesmanager,都是会话范围的),并且我无法连接到jsf 会话(FacesContext.getCurrentInstance() 为 null)。这是因为 flex 创建了一个新的 bean 实例,我认为它与 jsf 注入的当前实例不同。

我可以通过在java bean中创建一个新的实体管理器来从flex连接到数据库,但这不是我想要的,因为它又是另一个实体管理器...我想通过accessmanager-bean持久保存并获取数据。

我知道 exadel fiji 和 flamingo,但我无法使用 fiji,因为我的 jsf 应用程序包含icefaces 组件,但它无法与 fiji 需要的 richfaces 一起使用。火烈鸟仅适用于 jboss seam 和 spring。是吗?

我还阅读了有关 spring-flex-integration 的内容,但 jsf 应用程序不是用 spring 创建的,我不想将 spring 集成到如此大的 jsf 应用程序中。 昨天我读到了 FlexFactory 接口。这个接口我必须在我自己的工厂中实现,并将其设置在 blazeds 的 service-config.xml 中作为工厂 阅读此内容。我仍然实现我自己的工厂,但我只通过 servlet 上下文获取应用程序范围的 bean,这是我通过 FlexContext.getServletContext().getAttribute("Bean"); 获得的而不是会话作用域的 bean...

我希望有机会连接 throw flex 和 jsf... 谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉殇 2024-08-25 21:36:06

FacesContext.getCurrentInstance() 为 null

仅当当前请求通过FacesServlet 传递时才会发生这种情况。换句话说,请求 URL 与 FacesServleturl-pattern 不匹配。它负责创建线程本地 FacesContext 实例。

但实际上您在这里并不需要FacesContext。由于 JSF 仅在 Servlet API 的顶部运行,因此您也可以进入低级别并利用它来获取会话范围的托管 bean。 JSF 将会话范围的托管 Bean 存储为 HttpSession 的属性,并以托管 Bean 名称作为键。

因此,如果您有一个名为 myBean 的会话范围托管 bean,并且您手上有 HttpServletRequest,那么您还可以按如下方式访问它:

MyBean myBean = (MyBean) request.getSession().getAttribute("myBean");

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");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文