Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting started with JSF : JSF and Spring

 
Rafael Morales
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jesper De Jong,

In your book can I find  some examples about how to configure an App that needs to have JSF and Spring. I know this something crazy, but I have a customer who is requesting this, because in the view layer my customer wants to have Primefaces + JSF, however for the backside they need Spring + Hibernate, so it would be great if in your book you wirte about how mix two big frameworks like JSF with another.

Regards
 
Liutauras Vilda
Marshal
Posts: 3392
131
BSD
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a quick clarification, it isn't a book. It is a video series.
 
Rafael Morales
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, thank you for the correction
 
Tim Holloway
Bartender
Posts: 18467
61
Android Eclipse IDE Linux
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Incidentally, the quick answer to that question is that there's a JSF-Spring bridge that you can configure into the faces-config. It allows Spring beans to be referenced in EL exactly like JSF beans are and can be used to inject persistence interface services into Managed Beans. As well as other Spring services, such as email, scheduling, and so forth.

My typical large JSF/Spring/Hibernate-JPA app has a persistence service layer that deals with sets of related data and is transactional. This allows me to keep all the persistence Model objects detached while working in JSF code and in the View Rendering phase (which I personally recommend). The persistence service layer basically deals with data as business functions.

Below the persistence layer, I have a DAO layer. The JSF code never talks to anything in here directly, only via the persistence service layer (in extreme cases, that will make a persistence service class a mere proxy for the DAO, but such is life). The DAOs are Spring-injected into the persistence services that need them. The DAOs are the CRUD/Finder code for individual tables (or sometimes parent/child table sets), whereas the persistence services handle heterogeneous groups of tables (a "working set"). Like the persistence services, the DAOs are transactional, and they will inherit transaction context, so if a persistence transaction invokes DAO functions, all the DAO functions will commit or rollback when the persistence service does.

That's all it takes.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15753
74
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can indeed configure Spring's expression language resolver in faces-config.xml so that you can use Spring dependency injection instead of CDI (the Java EE standard API for dependency injection). In the project I'm currently working on, we are doing just that. It looks approximately like this in faces-config.xml:

 
Rafael Morales
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your answer!!! It works now
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!