Difference between Request MVC and Component MVC [closed]
Asked Answered
H

1

63

I have heard that JSF is implementing the component based MVC and Spring MVC is implementing the request based MVC. I would like to know what is the exact technical difference between these two types.

Hogtie answered 26/1, 2011 at 6:28 Comment(2)
Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.Boondocks
All due respect, a request for technical differences is not primarily opinion based.Insomuch
I
98

In request (action) based MVC, a single front controller servlet will delegate to action models based on request URL/params. You work directly with raw HttpServletRequest and HttpServletResponse objects in the action model. You've to write code yourself to gather, convert and validate the request parameters and if necessary update the model values before you can ever invoke the business action.

In component based MVC, a single front controller will gather, convert and validate request parameters and update the model values itself so that you only need to worry about the business action yourself. How the controller needs to gather/convert/validate/update the values is definied in a single place, the view. Since that's not possible with "plain" HTML, a specific markup language is required to achieve the goal. In case of JSF 2.0, that's XML (XHTML) based. You use XML to define UI components which in turn contain information about how the controller should gather/convert/validate/update the model values and generate/render the necessary HTML representation.

Advantages and disadvantages should be clear at this point: With a request based MVC framework you need to write more (boilerplate) code yourself to achieve the goal. However you end up with much more fine grained control over the process and the HTML/CSS/JS output. With a component based MVC framework you don't need to write much code yourself. However you have less fine grained control over the process and the HTML/CSS/JS output. So if you'd like to do things a bit differently than the standard describes and/or the implementation provides, then you'll waste a lot more time in a component based MVC framework when you're not well versed with its ins and outs.

Manfred Riem (JSF 2.x team member and ex Java EE 8 MVC 1.0 spec lead) has outlined it nicely during his speech about MVC 1.0 (JSR 371) on Devoxx 14:

photo

See also:

Insomuch answered 26/1, 2011 at 12:20 Comment(7)
Many people say that, in MVC model is representing the database. Is it true? Is it bean or database?Hogtie
No, it does not explicitly represent the database. In Java world, the model is just a Javabean. The Javabean in turn can also be a database entity. It's then exactly that class which is been used by JDBC or JPA code to map/transfer the values between Java runtime environment and the database table.Insomuch
so that makes asp .net mvc component based , rite ?Rainband
asp.net mvc is request based, it's stateless and based on GET/POST mechanism.Scranton
@Insomuch Are there remarkable differences between these two types regarding handling of the lifecycle of asynchronous HTTP (AJAX) requests? Or do I misunderstand something?Skidproof
+1 for posting the picture of Manfred Riem's presentation at Devoxx. I had that exact slide in mind when googling for this topic.Belldas
Fast forward to 2023, @Rainband and Omar Salem, when you use Blazor with ASP.net then it becomes component-based. ASP MVC is still request (action) based.Brokaw

© 2022 - 2024 — McMap. All rights reserved.