JSF 2.0 - bean 范围的可能性

发布于 2024-10-28 12:30:37 字数 1165 浏览 2 评论 0原文

我发布了几个问题,但尚未得到任何答复。我在这里所说的一切主要涉及 JSF 2.0.*。

典型的 Bean 包含要在页面上显示的信息。常见的基于 Web 的业务应用程序是一组页面,其中每个页面都涉及查看-编辑-保存状态,并由多个 xhtml 页面表示。因此,我们创建一个 bean 来管理这些状态。但有几个问题我将很快描述:

1) 每个页面都是不同的视图,从而迫使您将 bean 放入会话范围。它会导致会话存储膨胀。
2) 在视图之间传递参数。为了编辑文档,人们应该知道文档的 ID 或/和另一组对象。将它们放入会话中并不是一个好的决定(臃肿的会话反模式)。

到目前为止,已经尝试了几次纠正这种情况的尝试。

a) t:saveState。多年来它一直在履行自己的职责。但现在我们正在摆脱它。 b) 接缝对话。它带来了很多关于谈话结束的确切时刻的问题。超时不是一个容易设置的参数,因为我们不知道业务用户将编辑文档等时间。这对我们来说不是解决方案。
c) CODI(未尝试) 这似乎是一个不错的 JSR 299 实现,并且有可能解决所有问题,但它很少有文档记录,并且由于是扩展,因此坚持使用 WELD另一个框架,我们只想使用 JSF 的所有功能。
d) Spring Web 流。嗯,这是一个非常好的框架,文档丰富,出色的 IOC 容器、流程范围以及它提供的所有其他好东西都可以作为补救措施。它解决了乘法选项卡问题(这是我的措辞,所以如果不清楚我的意思请原谅我)。假设我们有一个编辑页面和视图作用域 bean,并且我们正在填写表单。如果用户在新选项卡中打开另一个页面,则会触发 GET 请求并且 bean 超出范围。 Web 流可以识别此类问题,并在打开新选项卡时启动新流。

(Web Flow 的续集)但它是单一的,将迫使我们重写整个项目。是的,我知道它支持 JSF,并且我已经测试并摸索了一段时间,看看它是否符合要求。并不是因为它的安全性。不幸的是,我们没有时间也没有资源从头开始构建新项目。

我们几乎已经没有解决方案了。 JSF 是一个很棒的框架,已经过广泛的测试并在许多项目中使用。但开发商拒绝将CDI纳入其中。

任何人都可以推荐任何解决方案来解决单个 bean 的编辑-查看-保存问题吗?任何架构建议都会有很大帮助。预先非常感谢您。

I posted a couple of questions but haven't gotten any reply yet. Everything I state here concerns JSF 2.0.* mostly.

A typical bean contains information to be displayed on a page. Common business web-based application is a set of pages where each of them involves view-edit-save state which are represented by several xhtml pages. So we create a single bean to manage those states. But there are several problems I will describe shortly:

1) Each page is a different view thus forcing you to place bean into a session scope. It takes its toll in bloating the session storage.
2) Passing parameters between views. In order to edit a document one should know ID of the document or/and another set of objects. Placing them into a session is not a good decision (bloated session antipattern).

So far several attempts to rectify a situation have been tried.

a) t:saveState. It has been doing its job for many years. But now we are getting rid of it.
b) Seam conversation. It has imposed so many problems concerning an exact moment the conversation dies. Time out is not an easy parameter to be set since we don't know how long a business user will, for example, be editing a document. Not a solution for us.
c) CODI(not tried) It seems to be a nice JSR 299 implementation and, potentilly can solve all out problems but it is so scarcely documented and, since being an extension, sticks to the WELD which is another framework and we just want to use all the power of JSF.
d) Spring web flow. Well, it is a very nice framework, documented abundantly, great IOC container, flow scope and all other nice things it provides can be a remedy. It solves multiply tab problem(it is my wording, so forgive me if it is unclear what I am getting at). Imagine we have an edit page and view scoped bean and we are filling the form. If users opens another page in a new tab, GET request is fired and the bean goes out of scope. Web flow can recognise such a problem and starts a new flow if a new tab has been opened.

(continuation on Web Flow)But it is monolithic and will force us to rewrite the whole project. Yes, I know it supports JSF and I have tested and fumbled with it for a little while to see whether it fits the bill or not. It doesn't because of its security. Unfortunately we don't have time nor resources to build a new project from scratch.

We have almost run out of solutions. JSF is a great framework, has been tested extensively and used in many projects. But the developers refuse to include CDI in it.

Can anyone recommend any solution to edit-view-save problem with a single bean? Any architectural advice will be of great help. Thank you so much in advance.

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

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

发布评论

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

评论(2

时光礼记 2024-11-04 12:30:37

首先:这与其说是一个问题,不如说是一次讨论,所以永远不会有明确的“是”或“否”...除了客观论证之外,总是有优点和缺点(开发人员不喜欢它) ;-)

无论如何,让我首先确定您的情况对于所有类型的 Web 应用程序来说都很常见,并且您所描述的问题对于每个从架构角度思考 Web 应用程序开发的人来说更为常见看法。

一年前面临着几乎相同的场景,这是我们的架构:

Java EE 6 与 JSF 2.0、CDI(+ EJB 3 和 JPA,但这超出了本答案的范围)。

  • ViewScoped Bean,每个视图一个(JSF ViewScope 使用 Seam 3 Faces 连接到 CDI)
  • ConversationScoped SFSB 作为业务逻辑的门面每个用例,事务/安全边界(外观被 1 - n 个视图控制器引用)
  • RequestScoped 服务(无状态,可重用为其他客户端(通过不同的外观)

所有这些都像一个魅力,之间几乎没有粘合代码各层。

1) 每个页面都是不同的视图,因此
强迫你将 bean 放入
会话范围。它付出了代价
使会话存储膨胀。

2) 在视图之间传递参数。
为了编辑文档,应该
知道文档的 ID 或/和另一个
对象集。将它们放入一个
会议不是一个好的决定
(臃肿的会话反模式)。

我绝对支持你。这就是我们使用对话的原因。

b) 接缝对话。它强加了
如此多的问题都与精确的
谈话结束的那一刻。暂停
不是一个容易设置的参数
因为我们不知道需要多长时间
例如,商业用户将是
编辑文档。不是解决方案
我们。

凭借 3 年 Seam 2 / 3 的生产经验,我向您保证这绝对是可以管理的。对话就像手套一样适合某个用例,一段时间后您就不想再使用其他任何东西了。当然不是会议;-)

c) CODI(未尝试) 这似乎是一个
很好的 JSR 299 实现,
可以解决所有问题
但它几乎没有被记录下来,
既然是扩展,就坚持
WELD 这是另一个框架
我们只想使用所有的力量
JSF 的。

如果您想使用 CODI,则不需要 Weld,两者都是 JSR 299 实现。在撰写本文时,Weld 的文档更加完善,使用也更加频繁。我什至不知道CODI是否是最终的?

d) Spring Web 流。嗯,这是一个非常
不错的框架,文档丰富,
出色的 IOC 容器、流量范围和
它提供的所有其他好东西都可以
成为一种补救措施。它解决了乘法选项卡
问题(这是我的措辞,所以请原谅
如果不清楚我得到什么,我
在)。想象一下我们有一个编辑页面
查看作用域 bean,我们正在填充
形式。如果用户打开另一个页面
在新选项卡中,触发 GET 请求并
bean 超出范围。网页流量
能够认识到这样的问题并且
如果新选项卡有则启动新流程
已打开。

Seam / Weld / CODI 也解决了多选项卡问题。就这样九十了...

我们几乎没有解决方案了。
JSF 是一个很棒的框架,
广泛测试并用于许多
项目。但开发商拒绝
将 CDI 包含在其中。

JSF 的问题在于您的项目不是全新项目。您需要连接到后端,而使用纯JSF范围和技术将会遇到问题。

我只能告诉你:我也必须说服我的同事使用 CDI。我用所描述的布局中的工作原型完成了它,现在,一年后,团队中的每个人都对我们的技术堆栈非常满意...:-)

总结这个相当冗长的答案:

Java EE 6 是伟大的技术堆栈这类应用程序,您应该尝试一下。您所描述的问题不仅可以通过 Java EE 6解决,而且是规范团队在设计 API 时考虑的问题。

如果您愿意,请随时发布更多问题/疑虑。

First of all: this is rather a discussion than a question, so there will never be a clear 'yes' or 'no'... There are always pros and cons beyond objective arguments (the developers dont like it) ;-)

Anyhow, let me start with the ascertainment that your situation is very common for all kind of web applications, and the problems you are describing are even more common for everyone who thinks about web application development from a architectural point of view.

Being confronted with an almost identical scenario over a year ago, here is our architecture:

Java EE 6 with JSF 2.0, CDI ( + EJB 3 & JPA, but this is beyond the scope of this answer).

  • ViewScoped Beans, one per View (JSF ViewScope connected to CDI with Seam 3 Faces)
  • ConversationScoped SFSB as facade per usecase for the business-logic, transaction / security boundary (facade being references by 1 - n view controllers)
  • RequestScoped Services (stateless to be reusable for other clients (through different facades)

All this works like a charm, with almost no glue code between the layers.

1) Each page is a different view thus
forcing you to place bean into a
session scope. It takes its toll in
bloating the session storage.

2) Passing parameters between views.
In order to edit a document one should
know ID of the document or/and another
set of objects. Placing them into a
session is not a good decision
(bloated session antipattern).

I'm absolutely with you. That's why we use conversations.

b) Seam conversation. It has imposed
so many problems concerning an exact
moment the conversation dies. Time out
is not an easy parameter to be set
since we don't know how long a
business user will, for example, be
editing a document. Not a solution for
us.

With 3 years experience of Seam 2 / 3 in production, I assure you that this is absolutely manageable. A conversation fits a usecase like a glove, and after a while you don't want to use anything else again. And certainly not the session ;-)

c) CODI(not tried) It seems to be a
nice JSR 299 implementation and,
potentilly can solve all out problems
but it is so scarcely documented and,
since being an extension, sticks to
the WELD which is another framework
and we just want to use all the power
of JSF.

If you want to use CODI you dont need Weld, both are JSR 299 implementations. At the time of writing, Weld is far better documented and used more often. I don't even know if CODI is final?

d) Spring web flow. Well, it is a very
nice framework, documented abundantly,
great IOC container, flow scope and
all other nice things it provides can
be a remedy. It solves multiply tab
problem(it is my wording, so forgive
me if it is unclear what I am getting
at). Imagine we have an edit page and
view scoped bean and we are filling
the form. If users opens another page
in a new tab, GET request is fired and
the bean goes out of scope. Web flow
can recognise such a problem and
starts a new flow if a new tab has
been opened.

The multitab problem is solved by Seam / Weld / CODI as well. That's so ninetieths...

We have almost run out of solutions.
JSF is a great framework, has been
tested extensively and used in many
projects. But the developers refuse to
include CDI in it.

The problem with JSF is that your projects are not greenfield. You need to connect to a backend, and you will have problems doing this with pure JSF-scopes and technologies.

All I can tell you: I too had to convince my co-workers to use CDI. I did it with a working prototype in the described layout, and now, a year later everyone in the team is quite happy with our technology stack... :-)

To summarize this rather lengthy answer:

Java EE 6 is great technology stack for that kind of applications, and you should give it a try. The problems you are describing are not only solvable with Java EE 6, instead they were rather the problems the spec team had in mind when they designed the APIs.

Feel free to post further questions / doubts, if you like.

单挑你×的.吻 2024-11-04 12:30:37

一般说明:

OpenWebBeansWeldCanDIJSR-299 实现,因此真正的容器提供管理上下文实例、上下文、事件等的功能。

CODI是一个可移植的JSR-299扩展(如Seam3),它将运行在任何 CDI 容器。您可以在上述所有 CDI 容器上使用 CODI。

CODI 基本上提供了一些不同的东西:

1.) 一个核心模块,其中包含有用的东西,如 @ProjectStageActivated(基于 JSF ProjectStage 启用/禁用 bean)、可注入消息,

2.) JSF 支持模块,具有许多附加范围,如 @ViewAccessScoped 、@WindowScoped(每个窗口的 bean)、@ConversationGroup、类型安全的 @View 导航、CDI @PhaseListener 等

3.) JPA @Transactional 支持。这将为您提供轻松的持久性,而无需使用 EJB

Just a general note:

OpenWebBeans, Weld and CanDI are JSR-299 implementations, thus the real containers providing the functionality of managing contextual instances, contexts, events, etc.

CODI is a portable JSR-299 Extension (like Seam3 is) which will run on any CDI container. You can use CODI on all the CDI-containers mentioned above.

CODI basically provides a few different things:

1.) a core module which contains useful stuff like @ProjectStageActivated (enabling/disabling beans based on the JSF ProjectStage), injectable Messages,

2.) JSF support modules with lots of additional scopes like @ViewAccessScoped, @WindowScoped (bean per window), @ConversationGroup, type safe @View navigation, CDI @PhaseListener, etc

3.) JPA @Transactional support. This will give you easy persistence without the need of using EJBs

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