I've a Java webapp with these frameworks and I want to know if my implementation meets with MVC pattern:

Controller Layer (V)

I'm using JSF

public class Controller{
    private Business business;

    public void insert(){

Business Layer (C)

I'm using Spring

public interface Business{
    public void insert();

public class BusinessImpl implements Business{
    private DaoMapper mapper;

    public void insert(){

Data Layer (M)

I'm using MyBatis (This java interface is associated to XML file of MyBatis)

public interface DaoMapper{
    public void insert();

My layers implemented MVC pattern? I'm confused :S...


Your code specifically implementing MVC pattern then No but is it actually MVC, well that answer is YES.

As Bart van Ingen Schenau points out the data as well as behavior to retrieve the appropriate data are encompassed by the model. This is correct but the important thing to remember about JSF is that the framework itself is inherently MVC.

JSF Model

The managed bean and Spring injected business logic encapsulates the model.

JSF View

Your XHTML markup represents the View components. This markup also contains Controller hooks that bind your Model (Managed Beans, ORM entities, etc...) to the View components.

JSF Controller

This is just FacesServlet. It is the controller that creates the interaction between View and Model so that the web developer doesn't need to worry about this.

  • I already know that my webapp have two frameworks that implemented MVC pattern (JSF and Spring) apart MyBatis that's ORM. That's why I have doubt that as the MVC pattern applies to my webapp if I have two frameworks MVC. In my particular case my implmentation is so: V = > page XHTML and JSF Framework, C => Spring beans or only FacesServlet class?, M: Database, MyBatis and Spring beans? – Cesar Miguel May 26 '13 at 16:24
  • @CesarCasasola Unless you are using Spring MVC then plain Spring is just a Dependency Injection framework and that has nothing to do with MVC. Your controller is just FacesServlet. Your model is all JSF Managed Beans, Spring Beans, business logic and MyBatis. The model is where most of the interesting application stuff will exist anyway. – maple_shaft May 26 '13 at 16:35
  • Oh, Ok. Everything is clearer :) and I supose that implementation layers is independent of MVC pattern? MVC pattern don't implied only three layers. Right? – Cesar Miguel May 26 '13 at 16:39
  • @CesarCasasola MVC pattern don't implied only three layers. Right? I am not sure I understand sorry. Your JSF implementation is automatically MVC because of the JSF framework. Just like if you instead use Spring MVC your implementation is automatically MVC. I hope this makes sense. – maple_shaft May 26 '13 at 16:53
  • 1
    @CesarCasasola: MVC does not imply any layers at all. In typical depictions, MVC is shown as three circles arranged in a triangle, with arrows indicating the communication paths. – Bart van Ingen Schenau May 26 '13 at 16:57

No, your layers, as described, do not implement the MVC pattern.

Within the MVC pattern, the Model contains most of the application-specific logic, in particular the business logic and all the layers below it. So, in your three-layer structure, that would be both the Business and the Data layers.

The View contains the code for driving the the user interface. The View classes produce the HTML, JSON or XML that gets displayed by the browser.

The Controller classes tie it all together. They receive the requests from the browser, and instruct the Model and View to take the relevant actions based on that request.

  • Well...As you mention: V => XHTML files, JSF beans? C => Class that managed Request. In my case should be FacesServlet class. It's ok? M => All tables, procedures, function, etc of database – Cesar Miguel May 26 '13 at 16:01
  • @CesarCasasola: Yes, that sounds more like it, but I am not familiar enough with the specific Java technology to tell for sure. – Bart van Ingen Schenau May 26 '13 at 16:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.