• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Are there advantages into integrating Spring into JSF?

 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Saloon Keeper
Posts: 25466
180
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jehan Jaleel
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 25466
180
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Been there. Done that. Went back for more. But this time, I took this tiny ad with me:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic