困惑:与经典 MVC 控制器相比,JSF2 中 Bean 的作用
我有一个与设计和架构更多相关的问题。我有基于经典 MVC 的背景,必须亲自接触 JSF2。我阅读了有关 JSF2 的 IBM 文章 (http://www.ibm.com/developerworks /library/j-jsf1/)并认为我理解总体概念。
我通过ROO开始接触JSF2。我有一种感觉,ROO(也许这对于任何 JSF2 类型的应用程序都是如此,也许不是)正在对 bean 进行非常奇怪/不清楚的使用。一般来说,我真的不清楚 Bean 的实际作用是什么!例如,如果我有一个带有用于编辑单个用户条目的表单的视图,我将在 a 中初始化用户,我们将其称为 UserBean (可能将其存储在成员变量中)并通过 getter 访问此变量。如果我现在想要概述所有用户,我将再次在 UserBean 中呈现视图,保存用户集合,并再次通过 getter 访问该集合。前面的描述实际上是我使用 jsf 做事的方式。这意味着我将 UserBean 更多地用作有状态服务作为控制器。
在典型的控制器情况下,我将为每种类型的操作(列出用户、编辑用户、查看用户等)创建一个单独的控制器,并具有特定的初始化数据,这样我将通过控制器分离逻辑的上下文。
我经常使用特定于上下文的服务,例如,如果我经常处理用户在应用程序中的分布,我会创建一个用户服务来处理特定于用户的逻辑,该逻辑可能太复杂而无法放入其自身中。例如,如果我现在研究 roo 生成的 Bean,我会找到以编程方式呈现表单、输入字段和标签的方法,这些方法再次存储用户列表、指示数据是否已加载的布尔字段、单个用户成员等等更像是放入 UserService (或其他)的方法。我想知道这是否是 JSF2 的预期使用方式,换句话说:将与一个上下文相关的所有内容推送到 bean 中,不使用服务,并编写处理所有内容的“超级控制器 bean”。
我真的不知道你的问题是否正确,但可能对我有帮助的是,
- 一个非常具有示范性和值得称赞的示例应用程序的提示,该应用程序以与 jsf2 功能结合使用的方式使用 bean 和例如,围绕给定类型的实体实现基本 CRUD 用例。 (一个令人困惑的大问题是,在我的例子中,ROO 总是使用 AJAX 和 javascript 的东西,比如 Modal-Dialogs 来实现 CRUD 逻辑。我想知道 JSF 是否有一种更经典的方法来实现这一点? [使用“经典”我例如,表示基于 URl 的视图和用于列出、编辑和查看实体的分离视图])
- 一种启发典型“好人做事的方式”JSF 模式的资源(也许这是 J2EE 模式?)。
太感谢了!
如果我不清楚,请随时督促我具体说明具体要点!
I have a question that is more design and architecture related. I am coming from a classical MVC based background and have to get my hands dirty on JSF2. I read the IBM articles on JSF2 (http://www.ibm.com/developerworks/library/j-jsf1/) and think I understand the overall concept.
I started to get in touch with JSF2 through ROO. I have the feeling that ROO (maybe this is true for any JSF2-Type App, or maybe not) is making very strange/unclear use of beans. It is in general really not clear to me what the actual role of a Bean is! For example, if I have a view with a form that is for editing a single user-entry, i would initialize the user in a, lets call it UserBean (maybe store it in a member variable) and access this variable trough getters. If i now want to overview all users, I would again render the view in in the UserBean hold a collection of users and again access this collection through getters. The previous description is actually the way i would do things with jsf. This means I would user the UserBean more as a stateful-service as a controller.
In a typical controller situation i would create for every type of action (list user, edit user, view user, etc) a separate controller, with specific initialized data and this way i would separate the context of the logic by controllers.
I often use context-specific services, e.g., if I handle user's often an spread over the application, I create a user-service that handles user-specific logic that is maybe too complex to be put into itself. If I now for example look into roo generated Beans, I would find methods that programmatically render forms, input fields, and labels, that again store list's of users, Boolean fields that indicate if data had already been loaded, single user members and a lot of methods that more look like to be put into a UserService (or whatever). I am wondering if this is the way JSF2 is intended to be used, in words: pushing everything that is related to one context into on bean, not making use of service, and writing "super-controller-beans" that handle everything.
I don't really know if you get the question right, but what would maybe help me is, a hint to
- a very exemplary and commendable example application that makes use of beans the way they were intended to be used in combination with jsf2 features and usecases that for example implement basic CRUD usecases around a given type of entity. (One big confusing point is, that in my case ROO always makes use of AJAX and javascript stuff like Modal-Dialogs to implement CRUD logic. I wonder if with JSF there is a more classical way to to this? [With 'classical' I mean for example URl-based views and separated views for listing, editing, and viewing entities])
- a resource that enlightens typical "thats-the-way-the-good-guys-do-it" JSF-Patterns (maybe this is J2EE Patterns?).
Thank you so much!
Please feel free the push me to concretize specific points if I am not clear!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您发布的 JSF2 链接指向 JSF1.2 文章。如果您想开始使用 JSF2 或 JSF,我建议您点击以下链接。
我建议从普通的普通 JSF 开始,而不是使用 JSF 的 ROO 来掌握 JSF。
回答您的问题
希望这有帮助。
The link for JSF2 you have posted points to JSF1.2 article. In case you want to start of with JSF2 or JSF I suggest following links.
I'll suggest start with plain vanilla JSF rather than ROO with JSF to get a hang of JSF.
To answer your question
Hope this helps.