Struts2 和多个活动向导/工作流程
我目前正在开发一个 Struts2 应用程序,该应用程序集成了向导/工作流程以产生所需的结果。为了更清楚地说明,有一个业务对象在三个不同的页面上发生了更改(主要是通过 AJAX 调用)。目前,我正在使用 ModelDriven 操作(由使用同一业务对象的所有操作扩展)以及 Scope 拦截器。虽然如果用户一次只处理一个业务对象的数据,这可以正常工作,但如果用户在多个选项卡中打开不同对象的向导(当我们想要更快地完成事情时,我们都会这样做),一切都会变得混乱,主要是因为我在会话中只存储了一个业务对象。
我读过一些关于使用对话范围拦截器的文章(主要文章)以及有关使用 Scope 插件 (此处)。然而,这两种方法似乎都有问题:
- Conversation Scope Interceptor 不会自动使对话过期,也无法与 Struts2 正确集成;
- Scope 插件缺乏适当的文档,最后一次构建是在 2007 年(实际上包括 Mark Menard 在定义 Conversation Scope Interceptor 时编写的一些想法,尽管它不使用相同的代码)。
Spring的WebFlow插件目前看来有点太复杂,无法使用。我目前正在寻找可以在几个小时内实现的东西,尽管我不介意您是否可以根据需要提出一些可行的东西,即使它需要的时间比我现在想要花的时间更多。
那么,经验丰富的 Struts2 开发人员,您有何建议?我应该如何实施这个?
I'm currently working on a Struts2 application that integrates a wizard / workflow in order to produce the desired results. To make it more clear, there is a business object that is changed on three different pages (mostly with AJAX calls). At the moment I'm using a ModelDriven action (that's extended by all the actions working with the same business object) coupled with the Scope interceptor. While this works okay if the user is handling data for only one business object at a time, if the user opens the wizard for different objects in multiple tabs (and we all do this when we want to finish things faster) everything will get messy, mostly due to the fact that I have only one business object stored in the session.
I have read a few articles about using a Conversation Scope Interceptor (main article) and about using the Scope plug-in (here). However, both approaches seem to have problems:
- the Conversation Scope Interceptor doesn't auto-expire the conversations, nor does it integrate properly with Struts2;
- the Scope plug-in lacks proper documentation and the last build was made in 2007 (and actually includes some of the ideas written by Mark Menard when he defines his Conversation Scope Interceptor, though it doesn't use the same code).
Spring's WebFlow plug-in seems a bit too complex to be used at the moment. I'm currently looking for something that can be implemented in a few hours time, though I don't mind if you can suggest something that works as needed, even if it requires more time than I'd currently want to spend on this now.
So, seasoned Struts2 developers, what do you suggest? How should I implement this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,这不是一个完全成熟的想法。但鉴于没有其他人提供任何东西,这就是我要开始的内容。
1)看看是否可以将整个流程移动到一个页面中。我坚信页面越少越好。它根本不会降低应用程序的复杂性,但用户通常会发现界面更加直观。最简单的方法之一是使用 json 插件和对 json 服务的大量 ajax 调用。
2)如果您必须在页面之间进行转换(或者只是认为实现#1 的客户端工作太多),那么我会查看 s:token 标记。启动流程的第一个页面将使用此标签,它将在每次调用时创建一个唯一的值。您将在模型对象会话中存储地图。需要通过从会话中查找模型来为操作提供模型。
#2 存在一些挑战。一是如何防止会话获取太多域对象? a) 好吧,这可能并不重要,如果会议设置为六个小时,您可以相当肯定,一夜之间它们就会被清理干净。 b) 提供了一个自我管理接口,可以获取/设置/列出会话中的对象。这可能是你一开始想到的,但它会让一个工人做一定的工作,然后停下来工作另一个。如果工作单元有一些有意义的名称(发票号码或其他名称),它可能会非常有用。
更复杂一点的方法是将模型对象从会话中移出并移入服务层。在插入时,您将设置插入时间。您可能需要一个管理器来保存每种类型的模型对象,并且每个管理器都有一个守护线程,该线程会定期扫描域对象的映射并清除过期的对象。
您可以通过使用令牌启动流程,然后在每个页面上使用另一个令牌来找出更复杂的系统。分别“flowId”和“currentPageId”,然后您可以绘制允许的过渡。
请注意,此时 Spring Web 流程开始看起来相当不错。
Okay this isn't a fully baked idea. But seeing as no else has provided anything, here is what I would start with.
1) See if you can move the whole flow into a single page. I'm a big believer in the less pages is better approach. It doesn't reduce complexity for the application at all, but the user generally finds the interface a lot more intuitive. One of the easiest ways to go about this is by using the json plugin and a lot of ajax calls to your json services.
2) If you must transition between pages (or simply think it is too much client side work to implement #1) then I'd look to the s:token tag. The very first page to kick off a flow will use this tag, which will create a unique value each invocation. You will store a map in your session of model objects. An action will need to be provided with a model by looking it up from the session.
There are a couple challenges with #2. One how do you keep the session from getting too many domain objects? a) Well it might not matter, if the session is set to say six hours you can be rather sure that over night they will get cleared up. b) provided a self management interface which can get/set/list objects in the session. It might be what you thought of at first but it would let a worker do a certain amount and then stop and work on another. If the unit of work has some meaningful name (an invoice number or whatever) it could be quite useful.
A little more sophistication would be to move the model objects out of the session and into the service layer. At which point when inserted you would set an insertion time. You would probably need a manager to hold each type of model object and each manager would have a daemon thread that would periodically scan the map of domain objects and clean out expired ones.
You can figure out more complicated system by kicking a flow off with a token and then using another token on each page. "flowId" and "currentPageId" respectively, then you can graph allowable transitions.
Mind you at this point spring web flow is starting to look pretty good.
现在有一个 Struts2 的对话插件,只需开发人员很少的工作即可实现所有这些目标: http://code.google.com/p/struts2-conversation/
它有:
- 嵌套对话
- 清理无效对话
-使用注释和命名约定的约定优于配置
- 继承的对话
- 与Struts2完全集成
- Spring IoC容器管理bean也可以使用会话范围
希望它对某人有帮助。
There is now a conversation plugin for Struts2 that achieves all these goals with very little work required by the developer: http://code.google.com/p/struts2-conversation/
It has:
-nested conversations
-cleanup of dead conversations
-convention over configuration with annotations and naming conventions
-inherited conversations
-fully integrated with Struts2
-the conversation scope can also be used by Spring IoC container-managed beans
Hope it helps somebody.