What components are MVC in JSF MVC framework?

2018-12-31 07:50发布

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

3条回答
梦寄多情
2楼-- · 2018-12-31 08:33

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:

查看更多
还给你的自由
3楼-- · 2018-12-31 08:48

The faces servlet manages the faces lifecycle so in that sense it is the controller combined with your own code that may get called during each lifecycle phase

http://www.java-samples.com/images/jsf-lifecycle.gif

查看更多
临风纵饮
4楼-- · 2018-12-31 08:49

M odel would be your ManagedBean

V iew would be jsp,XHTML (well you can accommodate various views here )

C ontroller will be FacesServlet

Update, hope this picture helps more

enter image description here

查看更多
登录 后发表回答