0

Since JSF managed beans are not part of a bean container, who manage them for example like Spring beans. Also how managed bean achieve the dependency injection with out a bean container?

How JSF would be a better replacement for Spring with out a bean managed container and with other functions Spring provides?

Harshana
  • 7,297
  • 25
  • 99
  • 173

1 Answers1

1

JSF is basically an MVC framework focused in the view layer. When comparing it with Spring, it could be an equivalent to Spring MVC, but never to the whole Spring framework, which has much more functions.

For your question of who manages the dependency injection, the own JSF framework used to do that, for me, as an example, I'm using Tomcat which is just a servlet container, so I use JSF for that work (this means I can only inject other managed beans and not a Service or a DAO).

In other cases, for JavaEE servers as JBoss or Glassfish, the server itself has an embeded container (which acts like the Spring framework) so you could delegate the injection to its CDI implementation.

Finally you tell about JSF being an Spring replacement. As I've said before, this makes no sense. JSF is a part of JavaEE specification and it's being oriented to be used with CDI injections. Spring MVC, being part of the Spring framework, could be the best choice if you manage your application with Spring instead of with a JavaEE container, although you could also use JSF instead of it.

Anyway, remember there's always the discussion of going with Spring or JavaEE. The first one, being a non-standard, offers a faster support and improvement releasing. On the other hand, JavaEE follows the Java specification, with all the benefits of that.

See also:

Community
  • 1
  • 1
Aritz
  • 30,971
  • 16
  • 136
  • 217
  • Suppose large scale project want to use JSF as MVC because its high support for view layer. So can we add core spring support also with JSF for DAO and Other service injection, define aspects and manage transaction etc. Or in that case we have to go with Spring MVC as JSF not support to use with other spring modules? – Harshana May 08 '14 at 09:52
  • It's actually possible to use Spring framework with JSF in order to perform DI in the managed beans. This involves, however, letting Spring manage the managed beans. Here you have some useful links: http://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/web-integration.html http://www.mkyong.com/jsf2/jsf-2-0-spring-integration-example/ To be honest, I tried it and had some problems with some JSF aspects as the view scope. – Aritz May 08 '14 at 09:57
  • Thank you for the answers. But mostly JSF is integrated with EJB know? – Harshana May 08 '14 at 10:04
  • 1
    It is with the whole JavaEE environment – Aritz May 08 '14 at 10:10