File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes Are there advantages into integrating Spring into JSF? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Are there advantages into integrating Spring into JSF?" Watch "Are there advantages into integrating Spring into JSF?" New topic
Author

Are there advantages into integrating Spring into JSF?

Jehan Jaleel
Ranch Hand

Joined: Apr 30, 2002
Posts: 196
Hi,

I was wondering what are the advantages, if any, of integrating Spring into a JSF 2 application? Does Spring buy us anything? Is there anything Spring can do for us which JSF does not do already?

Note I am only speaking about Spring, not Spring MVC. So instead of JSF managed beans we would have Spring beans like so...



Thanks,
Jahan
Jehan Jaleel
Ranch Hand

Joined: Apr 30, 2002
Posts: 196
Just to get this discussion started, it seems Spring container is more advanced than what JSF is using. For example it offers dependency injection and services like txn management and security.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15629
    
  15

Most of my webapps these days are Spring+JSF. Spring handles the persistency layer as well as various other plug-in services (such as for example, mailing, where I employ a dummy mailer for testing).

JSF also does dependency injection. My recommendation on security is that the primary security provider be J2EE container security, which you can then build on, as needed. I've see one or 2 mainstream webapps that use that technique for the coarse-grained security plus Spring security for the fined-grained stuff and it works well for them.

The primary reason for using both platforms is that while Spring excels at general-purpose java needs, JSF has more power in the specific area of MVC-based web GUI support. Since they play well together, I get the best of both.


Customer surveys are for companies who didn't pay proper attention to begin with.
Jehan Jaleel
Ranch Hand

Joined: Apr 30, 2002
Posts: 196
Thanks Tim for your response.

Just wondering what is your preference for component management, JSF managed beans or Spring? I personally feel the Spring container is better at managing my beans so I just add...

<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>

to my faces-config to tell JSF to look in Spring for its beans.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15629
    
  15

I use JSF for the MVC Models and Spring for the other stuff and use the resolver to ensure that they're all in the same namespace.

Spring beans are typically singletons, existing for the lifespan of the application. The J2EE equivalent would be (roughly) Application Scope. However, most of what I need for UI models is Session, View, or (rarely) Request scope. JSF is better for that, since it's wired into the MVC framework and can instantiate those objects on-demand. And, in the case of View scope, destroy them as well.

So my View templates are almost exclusively referencing JSF Managed Beans. The Managed beans get both other Managed Beans and Spring Beans injected into them. The persistence interfaces are Spring - as are other non-GUI singleton objects. The View-to-View data exchange is JSF.

The lines are gradually blurring as we move to a more unified model of bean control (CDI), but that's how I'm currently doing it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Are there advantages into integrating Spring into JSF?
 
Similar Threads
What else is Spring good for?
Anyone here have luck integrating JSF with...
JSF become RESTful
Spring Framework features and advantages?
Is the faces-config modularized