What components are MVC in JSF MVC framework?

JavaModel View-ControllerDesign PatternsJsf

Java Problem Overview


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

Java Solutions


Solution 1 - Java

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.

enter image description here

Solution 2 - Java

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

Solution 3 - Java

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

Solution 4 - Java

Java Server Faces is an MVC web framework where the MVC components are as follows,

  1. Model - It is the managed bean class annotated with @ManagedBean, which has properties to hold the data and respective getters and setters. The managed bean class can also contain the business logic.These are also known as backing beans which can have different scopes like request, session, application.

  2. View - The user interface shown to the client i.e. .xhtml files. It gets the data from the managed beans and it is rendered as the response.

  3. Controller - javax.servlet.webapp.FacesServlet is the centralized controller class which is basically a servlet. Any request that comes to the JSF first goes to the FacesServlet controller. Unlike the JSP in which we write our own controller class, in JSF the controller servlet is a fixed part of the framework and we do not write it.

MVC flow-

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionyegor256View Question on Stackoverflow
Solution 1 - JavaBalusCView Answer on Stackoverflow
Solution 2 - JavajmjView Answer on Stackoverflow
Solution 3 - JavaDonView Answer on Stackoverflow
Solution 4 - JavaHetal RachhView Answer on Stackoverflow