在EJB JSF中的一个会话中存储实时同步版本 [英] Storing entities for simultaneous edition in one session in EJB JSF

查看:150
本文介绍了在EJB JSF中的一个会话中存储实时同步版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JSF,EJB和JPA中创建Web应用程序时遇到了意识形态问题。

We have an ideological problem while creating a Web Application in JSF, EJB and JPA.

我们的示例情况是:

Admin显示数据表中的用户列表。接下来,他选择user1,这将引导他进入新的用户版网站。如果他尝试打开第二张卡或窗口并在同一会话中选择user2进行同步编辑,则会出现此问题。
当我们尝试在版本之后保存user1数据时,它是不可能的,因为它被用户2在端点中覆盖。

Admin displays the list of users in datatable. Next, he selects user1, which leads him to new user-edition site. The issue occure if he tries to open second card or window and select user2 for simultaneous edition in the same session. When we try to save user1 data after edition it is not possible, because it is being overwritten in Endpoint by user2.

数据存储:
因为我们没有在我们项目的View部分中存储任何数据[下图可用],所以在显示它之后,Managed Beans正在被销毁。因此,在Controller部分中,我们决定将当前选定的用户保留为Endpoint [Stateful EJB Bean]中的字段,该字段对于会话为常量,因为它由Session Scoped Managed Bean持有。
我们认为我们不应该在端点或会话范围管理Bean中存储任何集合。

Data storing: Because we do not store any data in View part of our project [diagram available below], after displaying it the Managed Beans are being destroyed. Therefore in Controller part we decided to keep the currently selected user as a field in Endpoint [Stateful EJB Bean] which is constant for a session as it is held by Session Scoped Managed Bean. We believe we should not store any Collections in Endpoint or Session Scope Managed Bean.

问题:
特殊情况是对情况的概述。在我们的应用程序中,我们希望在会话期间编辑相同类型的多个实体。

Problem: Particular case is an overview of the situation. In our application we want to edit multiple entities of the same type during on session.

问题:
我们应该在何处以及如何存储用户/的当前选择管理员,导致所选实体的版本。

Question: Where and how should we store the current selections of User/Admin, which lead to edition of that selected entity.

在视图中存储数据,请求范围部分允许我们控制同一会话中的多个实体,尽管我们认为它是不合适的方法。但是现在将它存储在控制器部分会导致在同一会话中编辑同一类型的一个实体的限制。

Storing data in view, request scoped part allowed us to control multiple entities in the same session, though we think it is not appropriate approach. But now storing it in controller part leads to limit of one entity of the same type being edited in the same session.

这里的图表: http://i.stack.imgur.com/9PyYr.jpg

推荐答案

由于您使用的是Java EE服务器(Glassfish 3.1),因此可以使用支持与JSF不同的范围的CDI。有一个名为 CODI 的CDI扩展,提供所谓的窗口范围,允许您根据浏览器窗口确定bean的范围,这将解决您的问题。有关窗口范围的更多信息,请访问此处

Since you are using a Java EE server (Glassfish 3.1) you could get advantage of using CDI which supports different scopes than JSF. There is a CDI extension called CODI which provides the so called "window scope", allowing you to scope your beans per browser window which will solve your problem. More info about the window scope can be found here.

另一种选择是使用也支持其自己的窗口范围的IceFaces JSF库。更多信息可以在这里找到。

Another option is to use IceFaces JSF library that also supports its own window scope. More info can be found here.

这篇关于在EJB JSF中的一个会话中存储实时同步版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆