MVC Pattern with JSF-Spring-MyBatis Web Applications

Architecturejavamvcweb-applications

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

@ManagedBean
public class Controller{
    @ManagedProperty("#{business}")
    private Business business;

    public void insert(){
        business.insert();
    }
}

Business Layer (C)

I'm using Spring

public interface Business{
    public void insert();
}

@Service("business")
public class BusinessImpl implements Business{
    @Autowired
    private DaoMapper mapper;

    @Override
    @Transactional
    public void insert(){
        mapper.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…

Best Answer

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.

Related Topic