aspose file tools*
The moose likes JSF and the fly likes Spring MVC 3 and JSF2 Integration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Spring MVC 3 and JSF2 Integration" Watch "Spring MVC 3 and JSF2 Integration" New topic
Author

Spring MVC 3 and JSF2 Integration

Khp Virajith
Ranch Hand

Joined: May 01, 2006
Posts: 85
Hi guys,

I'm planning to integrate JSF2 technology to an existing Spring MVC 3 based web application in order to provide rich user experience to the users. As I don't have previous experience on working with JSF2, I would like to hear your ideas and suggestions. Generally, I want to have a set of views which are served in terms of JSPs (Non-JSF) and the others are in Facelets (JSF). How should I configure Spring and JSF to achieve this? How view resolutionn should be done? For an example, there can be scenarios where a Facelet should be rendered as a result of a Spring MVC controller method invocation.

Feel free to share your expertise on this matter.


SCJP, SCWCD, SCMAD, SCSNI
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

I have apps that do something like that - mostly to generate XML files - but not rendering Spring MVC Controller into JSF. That would be pretty difficult, since the JSF MVC controller is supposed to control JSF views. You can only have one master view controller per URL request.

As far as using Spring MVC controller for JSPs, that's easy. You don't have to do anything. When you request a JSP, you get a JSP, when you request a JSF, you get a JSF. The URL router matches on your incoming URL to determine which controller is supposed to process the URL, and thereby what view will be selected to render it.


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

Joined: May 01, 2006
Posts: 85
Hi Tim,

Thanks a lot for your valuable response. Yes, you are right, it is pretty hard to mix both Spring MVC and JSF layer together as both have their own way of request handling.

I'm planning to use JSF together with Rich UI component library. And I want to use common JSF functionalities like validation, data conversion, etc. How would be the behaviour if I try to use a JSF page as a view of a request hanlder method in a Spring MVC controller? Will that JSF page behave as it is supposed to be? I mean, will validation, data conversion stuff work according to JSF spec? Will JSF lifecycle work with this approach properly? I'm trying to use following view resolver strategy. (Actually, I just tried this approach, but a NullPointerException is thrown unexpectedly when parsing the JSF page, So i just want to know if it does not work as my approach is wrong)



I would like to hear from you.

Khp Virajith
Ranch Hand

Joined: May 01, 2006
Posts: 85
[Adding some ideas to above mentioned post.]

Will it be beneficial to go with pure JSF model (having mapped URL so that it will be directly served by Faces servlet, other than Spring dispatcher servlet) rather than mixing stuff with both JSF and Spring MVC contrller layer?

What would you think?

Anyone is welcome to share your ideas and suggestions.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

I use Spring for my persistence layer, but for HTML, I prefer JSF. Like I said, however, I do find the SpringServlet to be useful when I want to output non-HTML content, such as XML.
Khp Virajith
Ranch Hand

Joined: May 01, 2006
Posts: 85
Hi Tim,

Thanks a lot for the reply.

After playing around Spring MVC and JSF, I have come to a conclusion to mainly go with JSF-based presentation layer and using Spring MVC as a supporting presentation technology to handle stuff which need not rich UIs and AJAX-based communications. Anyway, the challenging thing is to do the separation on which should be handled by JSF and which should be handled by Spring MVC.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring MVC 3 and JSF2 Integration