1

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...

asked May 26, 2013 at 7:46

2 Answers 2

1

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.

answered May 26, 2013 at 15:58
5
  • 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? Commented May 26, 2013 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. Commented May 26, 2013 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? Commented May 26, 2013 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. Commented May 26, 2013 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. Commented May 26, 2013 at 16:57
0

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.

answered May 26, 2013 at 14:14
2
  • 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 Commented May 26, 2013 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. Commented May 26, 2013 at 16:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.