views:

1259

answers:

4

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

+5  A: 

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

Nate
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.
+1 for great answer. Having used Struts and JSF for a few years now, I came to similar conclusions.
javashlook
+2  A: 

Request based framework is basically 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 basically as you can see, the flow is pretty much linear. So you're thinking in actions: what do user want (request) -> what user will get back (response). A really simple 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. A good example of it is actually 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 is IMHO Tapestry and Wicket. The paradigm that these two framework is truly 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.

jpartogi
Thanks jpartogi...so what do you think are pros and cons of these frameworks...
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).
jpartogi
A: 

but so many articles told that jsf is component based web development.so what it means?

idr
A: 

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

javance