Forums Register Login

Are there advantages into integrating Spring into JSF?

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
Police line, do not cross. Well, this tiny ad can go through:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2091 times.
Similar Threads
JSF become RESTful
Anyone here have luck integrating JSF with...
Spring Framework features and advantages?
Is the faces-config modularized
What else is Spring good for?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:13:32.