将JSF理解为MVC框架 [英] Understanding JSF as a MVC framework

查看:139
本文介绍了将JSF理解为MVC框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读JSF,我觉得为什么JSF是一个MVC框架(或者至少哪个部分属于哪个字母)我感到很困惑。

I am reading on JSF and I feel rather confused why JSF is a MVC framework (or atleast which parts belongs to which "letter").

我看了这个问题: JSF MVC框架中哪些组件是MVC?

如果您不在聚合视图中查看模型是您的实体,那么我在那里阅读,视图是您的XHTML代码,控制器是托管bean。嗯......好的,但是视图通常不依赖于执行进一步的业务逻辑调用,这些调用返回一组实体,例如,描述是否仍适用?

I read there if you don't look at it in an aggregated view the model is your entity, view is your XHTML code and controller is the managed bean. Hmm...Ok, but doesn't the view very often depend on carrying out further business logic calls which returns a set of entities for example, does the description still fit?

我读过的一本书描述为托管bean是Faces Servlet(Controller)用来调用业务层(Model)的某种消息,而XHTML代码就是视图。

One book I read described it as managed beans is the some kind of "message" bringer that the Faces Servlet (Controller) use to invoke the business layer (Model) and then the XHTML code is the view.

有太多的解释和差异,所以我不知道是哪种或如何理解它。

There are so many explanations and differences so I don't know which or how to understand it.

推荐答案

在JSF和许多其他Web框架中,它通常不完全清楚的部分原因是MVC模式最初是为桌面应用程序设计的。

Part of the reason why it's often not entirely clear in JSF and many other web frameworks which parts of it correspond to which part of MVC, is that the MVC pattern was originally devised for desktop applications.

在桌面应用程序中,节点M,V和C是最大连接图,这意味着每个部分都可以与其他所有部分进行通信。例如。如果模型更改,则可以将此更改推送到视图。如果桌面应用程序中存在多个视图表示,则尤其可见。更改一个,并实时查看其他更新。

In a desktop application, the nodes M, V and C are a maximum connected graph, meaning each part can communicate with every other part. E.g. if the model changes, it can push this change to the view. This is particularly visible in case there are multiple representations of the view in a desktop application. Change one, and see the other update in real-time.

由于Web应用程序的客户端/服务器和请求/响应性质,经典MVC不会映射1 :1到大多数Web框架。

Due to the client/server and request/response nature of web applications, classic MVC doesn't map 1:1 to most web frameworks.

具体来说,在JSF中,映射如下:

Specifically, in JSF the mapping is as follows:


  • 模型 - 服务/ DAO以及他们生产和使用的实体。对此的入口点是托管bean,但在Java EE(其中JSF是其中的一部分)中,这些工件通常分别由EJB和JPA实现。

  • 查看 - 将UI组件及其组成整页。这完全属于JSF领域,分别由JSF UIComponent 和Facelets实现。

  • 控制器 - 处理来自用户的命令和传入数据的交通警察,将其路由到正确的部分并选择要显示的视图。在JSF中,不会编写这个控制器,但它已经由框架提供(它是 FacesServlet )。

  • Model - The Services/DAOs plus the entities they produce and consume. The entry point to this is the managed bean, but in Java EE (of which JSF is a part) these artifacts are typically implemented by EJB and JPA respectively.
  • View - The UI components and their composition into a full page. This is fully in the domain of JSF and implemented by JSF UIComponents and Facelets respectively.
  • Controller - The traffic cop that handles commands and incoming data from the user, routes this to the right parts and selects a view for display. In JSF one doesn't write this controller, but it's already provided by the framework (it's the FacesServlet).

特别是最后一部分经常不太清楚:在JSF中你没有实现控制器。因此,支持bean或任何其他类型的托管bean NOT 控制器。

Especially the last part is frequently not well understood: In JSF you don't implement a controller. Consequently, a backing bean or any other kind of managed bean is NOT the controller.

第一部分(模型)也并非总是如此清楚地了解。业务逻辑可以由EJB和JPA实现,但是从JSF的角度来看,值绑定引用的所有内容都是模型。这也是其中一个JSF生命周期阶段的名称来自:更新模型。在此阶段,JSF将UI组件中的数据推送到模型中。从这个意义上讲,(JSF)托管bean就是模型。

The first part (the model) is also not always clearly understood. Business logic may be implemented by EJB and JPA, but from the point of view of JSF everything that is referenced by a value binding is the model. This is also where the name of one of the JSF life-cycle phases comes from: Update Model. In this phase JSF pushes data from the UI components into the model. In that sense, (JSF) managed beans are thus the model.

尽管JSF本身并没有明确定义这个概念,但是经常会出现一些特定用途的托管bean称为支持bean

Although JSF itself doesn't explicitly define the concept, there is an often recurring and specific usage of managed beans called the backing bean.

对于JSF,支持bean仍然是模型,但实际上它是一个位于中间的管道元素模型,视图和控制器。因为它执行一些可能被视为某些控制器任务的任务,所以这通常被误认为是控制器。但是,如前所述,这是不正确的。它也可以执行一些模型任务,偶尔也可以执行一些视图逻辑。

For JSF a backing bean is still the model, but practically it's a plumbing element that sits in the middle of the Model, View and Controller. Because it performs some tasks that may be seen as some controller tasks, this is often mistaken to be the controller. But, as explained before this is not correct. It can also perform some model tasks and occasionally do some view logic as well.

参见:

  • What are the main advantages of MVC pattern over the old fashioned 3-layer pattern
  • MVC-Architecture of JavaServer Faces (Chapter 4.3)

这篇关于将JSF理解为MVC框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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