Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What components are MVC in JSF MVC framework?

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

like image 750
yegor256 Avatar asked Feb 24 '11 11:02

yegor256


People also ask

What is MVC in JSF?

The JSF framework implements the Model-View-Controller (MVC) architecture ensuring that applications are well designed and easier to maintain.. According to the MVX pattern, a software component should be separated into layers along the following lines: Model.

What are JSF components?

A JSF user interface component is the basic building block for creating a JSF user interface. A particular component represents a configurable and reusable element in the user interface, which may range in complexity from simple (such as a button or text field) to compound (such as a tree control or table).

How does JSF framework work?

JSF technology is a framework for developing, building server-side User Interface Components and using them in a web application. JSF technology is based on the Model View Controller (MVC) architecture for separating logic from presentation.

What is the controller class name in JSF?

xml that a "FacesServlet" is responsible for handling JSF applications. "FacesServlet" is the central controller for the JSF application.


2 Answers

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:

  • JSF Controller, Service and DAO
  • Creating master-detail pages for entities, how to link them and which bean scope to choose
  • Passing a JSF2 managed pojo bean into EJB or putting what is required into a transfer object
  • Filter do not initialize EntityManager
  • javax.persistence.TransactionRequiredException in small facelet application

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.

enter image description here

like image 167
BalusC Avatar answered Oct 19 '22 06:10

BalusC


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

like image 26
jmj Avatar answered Oct 19 '22 08:10

jmj