-2

In java ee 7 it is recommended to use jsf as default presentation technology. JSP is deprecated as they say.

So to start with jsf i found that it uses managedbean which can handle events and provides data to views. It also manages pages flow.

So my questions are:

  1. is it is really recommended to use jsf model in java ee than what is the use of servlet?

As per my understanding managedbean extends servlet capability at some extent.

  1. If i wanted to use servlet in jsf based app how can i?

Can i use request and response objects in JSF managed bean? I would like to manually send response based on request and response cycle as Servlet does.

Ahesanali Suthar
  • 341
  • 3
  • 23
  • No this is not duplicate if you understand the context of my question. – Ahesanali Suthar Feb 10 '15 at 11:51
  • 1) Stack Overflow is wrong place for this question. 2) It's not different. That said, in future questions please ask one question per Question. – BalusC Feb 10 '15 at 11:59
  • @BalusC which is the right place than? – Ahesanali Suthar Feb 10 '15 at 12:02
  • A discussion forum. Stack Overflow is as being a Q&A site only intented for questions which can have **only one answer which is acceptable by everone in the world** and thus *not* only by yourself or only half of the world. – BalusC Feb 19 '15 at 10:15

1 Answers1

1

Yes, Java EE started with specific dedicated classes. Only late there came a POJO trend, with the use of annotations. Servlets form the earliest Java EE technology, but they are still very relevant. Also JSF needs a servlet container, providing the servlet related classes, But JSF is less tightly coupled, and there are uses outside the traditional web apps.

  1. The MVC model: beans for Model, JSF for View and servlet for Controller. A servlet might forward to some apt view/JSF after preparing data (beans). For special use cases servlets might be more suited or at least more direct, PDF generation, charts. Not to forget servlet filters.

  2. Let the URL map on a servlet. Annotations might be used. There prepare beans, which you can set and hold in any scope, the request scope being the most light and one-way. Then forward:

    request.getRequestDispatcher("/contact.jsf")
        .forward(request, response);
    

    Or from the ServletContext:

    context.getRequestDispatcher("/context/contact.jsf")
        .forward(request, response);
    

As there are many technologies out there for web-apps, you found a good solid starting point; it might be refreshing also trying other frameworks.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
  • i am not getting the point for last few sentances. – Ahesanali Suthar Feb 10 '15 at 12:29
  • You seem to be seriously studying the topic of web apps, and Java EE is a good foundation (especially as it used by web app frameworks internally). But with Java EE one has to realize there is much additional software. Before Java EE 6, Spring (MVC, Webflow) was the "better" solution. A mention that there is an entire ecosystem out there, – Joop Eggen Feb 10 '15 at 12:47
  • But today i like java ee more than spring. Working with spring is like a managing the project of jars. I found difficulties to manage lots of jars. Also jars are dependant i mean i have to choose right version of that jar. Where as in java ee it is pretty simple clean api no external jars required until you use the features which are not in java ee. It is lighter than spring. – Ahesanali Suthar Feb 10 '15 at 16:05
  • Nice to hear the somewhat same opinion, though Spring is a large tool chest with many goodies that influenced Java EE 6 too, – Joop Eggen Feb 10 '15 at 21:24