JSF MVC 框架中的 MVC 有哪些组件? [英] What components are MVC in JSF MVC framework?

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

问题描述

在 JSF MVC 框架中谁是模型、视图和控制器?

解决方案

这取决于观点(双关语).

在总体架构图中,您自己的 JSF 代码是 V:

M - 业务领域/服务层(例如 EJB/JPA/DAO)
V - 您的 JSF 代码
C - FacesServlet

在开发者图片中,架构 V 依次可划分如下:

M - 实体
V - Facelets/JSP 页面
C - 托管 bean

在较小的客户端图中,开发者V依次可划分如下:

M - JSF 组件树
V - 呈现的 HTML 输出
C - 客户端(网络浏览器)

在更小的 JavaScript 图中,客户端 V 依次可分如下:

M - HTML DOM 树
V - 视觉呈现
C - 事件侦听器功能(最终用户交互和 Ajax)

所以它基本上是一个 M(M(M(MVC)C)C)C ;)

请注意,一些初学者甚至一些—非常基本的—教程在托管 bean 中混合/复制/扁平化实体的属性,这将有效地使控制器成为模型.不用说,这是一个糟糕的设计(即不是一个干净的 MVC 设计).

以下答案中的代码片段说明了正确的 MVC 方法:

  • In JSF MVC framework who is Model, View, and Controller?

    解决方案

    This depends on the point of view (pun intented).

    In the big architectural picture, your own JSF code is the V:

    M - Business domain/Service layer (e.g. EJB/JPA/DAO)
    V - Your JSF code
    C - FacesServlet

    In the developer picture, the architectural V is in turn dividable as below:

    M - Entity
    V - Facelets/JSP page
    C - Managed bean

    In the smaller client picture, the developer V is in turn dividable as below:

    M - JSF component tree
    V - Rendered HTML output
    C - Client (webbrowser)

    In the yet smaller JavaScript picture, the client V is in turn dividable as below:

    M - HTML DOM tree
    V - Visual presentation
    C - Event listener functions (enduser interaction and Ajax)

    So it's basically a M(M(M(MVC)C)C)C ;)

    Note that some starters and even some —very basic— tutorials mingle/copy/flatten the entity's properties in the managed bean, which would effectively make the controller a model. Needless to say that this is poor design (i.e. not a clean MVC design).

    The code snippets in the following answers illustrate the right MVC approach:

    In the book The Definitive Guide to JSF in Java EE 8, in chapter 8 "Backing beans", page 276, the below Venn diagram is used to illustrate the position of the backing bean in the MVC paradigm within the context relevant to the JSF developer. Copyright disclaimer: book is written by me and picture is created by me.

    这篇关于JSF MVC 框架中的 MVC 有哪些组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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