Java Component based vs Request based frameworks
Asked Answered
S

4

49

I was recently asked in an interview - In java, how do you compare component based frameworks to request based frameworks? I explained EJB as an example of Component based framework and Struts as a request based framework but was not convinced if I did justice to the question.

Any ideas on what interviewer meant and what should have been compared??

regards, avajurug

Snodgrass answered 8/8, 2009 at 0:44 Comment(0)
G
84

They were most likely looking for examples of web frameworks - for example, JSF is a component-based framework, and Struts is a request-based framework.

Request-based frameworks generally make it clear through their APIs that they're working with parsing an HTML request / generating an HTML response, while Component-based frameworks attempt to abstract this away and treat the application as collections of components with renderers and actions to do things.

In my opinion, component-based web frameworks are more trouble than they're worth - their main purpose is usually to make the development of a web app "easier" for developers unfamiliar with web development, and closer to traditional desktop development. However, in practice, when something goes wrong, you need to develop custom components, you need to customize the framework for something that isn't "out of the box" functionality, etc. you need to understand both underlying "traditional" web development and how the component-based framework abstracts it - and if you're an experienced web developer and have existing solutions, utilities, libraries or snippets that worked in "traditional" web development, you'll waste time re-implementing them to work within the component-based framework.

Greeneyed answered 8/8, 2009 at 1:38 Comment(2)
Thanks Nate. I guess you are correct that probably they meant web frameworks. I am not familiar with JSF, so could not explain. Thanks for the answer.Snodgrass
+1 for great answer. Having used Struts and JSF for a few years now, I came to similar conclusions.Bilander
M
24

Request based framework is a web framework that gets user's request then determine what the system should do and give back the response back to the user. So the flow is pretty much linear. You're thinking in actions: what does user want (request) -> what user will get back (response). An example of Request based framework is Struts. The modern Grails is pretty much a Request based framework too.

Component based framework is not like that. There is actually no clear sense of the flow from front to back. An example of it is not JSF, because in some way JSF is pretty much quite the same with Struts (since the creator of Struts and JSF is the same). A good example of Component based framework Tapestry and Wicket. The paradigm in these two framework is different. You don't think in actions or request-response, but components and components. You define a component in your application, and you tell what the component does. But the flow does not have to be linear as in Request based framework.

Melonymelos answered 8/8, 2009 at 13:47 Comment(3)
Hmmh, that would be really subjective. It depends on your workflow in making a webapp. Component based framework is really good if you want to have a reusable components to be used by many different projects, Actions based framework is really good if you only need to send and receive Http request and http response (really useful in Ajax app).Melonymelos
JSF can't be categorized as non component based framework. Please refer JSF specification. JSF2.x Primefaces has rich sent of UI components.Lahdidah
JSF is indeed a component based framework. Though JSF saves the state of view between request-response cycle, and Tapestry 4 (don't know about tapestry 5) always returns to the pristine state of page at beginning of request. Both have pros and cons, but both of them are component based framework. Also the fact that creator of Struts and JSF are same doesn't mean that both will be pretty much same; they may or may not be.Dutton
I
5

JSF is component based java API, as said Nate, Struts is an action based framework, the Http requests are parsed, while processing the actions in the end the controler Servlet forwards the request to the JSP that will be responsible to generate the response. While in JSF which became a standard for component based web frameworks, there is actually no need to process the requests and the responses as all we need is to write JSP or XHTML pages, bind the components used in the page or the value they should render to properties in backing beans or managed beans and the FacesServlet (controller) does all the job to care about request parsing and redirecting to the JSP that will render the response based on navigation rules specified in faces-config.xml . So as you can see there is a big difference between Struts and JSF as JSF brings a component-event based approach while Struts is more close to the classic JSP/Servlet model. Another thing jpartogi have said the creator of JSF and struts is the same, I just want to mention that Struts is a framwork owned by Apache community while JSF is an API specified by JCP in the JSR-127 for the version 1.1 and JSR-252 for the version 1.2 and has different implementations (SUN-RI, Apache MyFaces...)

Isthmian answered 24/11, 2009 at 11:14 Comment(0)
N
3

Simply, If the framework has objects in java side for each web element so you can change attributes of it or add some functionality, it is component based framework but If framework does not provide objects and you have to put the response value of web element between its tags it is a request based framework.

Nonperformance answered 3/10, 2014 at 19:45 Comment(1)
What is this component?Indescribable

© 2022 - 2024 — McMap. All rights reserved.