I'm starting a new JSF (2) project. I realize that pure JSF has some limitation and I'm planning to drop in spring. JSF is a relatively new approach in spring (there is not even a tag spring-faces in stackoverflow :-) ), jsp being the classic way.
I need the best available adjustment of the technology stack.
1) do i need to use spring web flow too?
2) is it viable to use just spring faces (that seems to come as a part of web flow) + spring mvc+ JPA?
3) is there any good example of such a configuration?

- 7,477
- 20
- 77
- 137
2 Answers
I'm using JSF 2 together with Spring 3 for Dependency Injection etc.
I'm not familiar with Web Flow and I don't use it.
In your faces-config.xml
you can register the Spring SpringBeanFacesELResolver
.
<el-resolver>
org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver>
Then you can access Spring managed beans in your JSF code!
Have a look at the Spring documentation and the API docs.

- 2,534
- 2
- 26
- 28
-
So you don't use spring faces, but plain jsf 2, without file uploader, security etc. – AgostinoX Jun 22 '11 at 12:03
-
No, we don't use spring faces. (I even don't know exactly what this is...) We also use PrimeFaces, which has a file upload component: http://www.primefaces.org/showcase/ui/fileUploadHome.jsf. We are still at the beginning of our project, so I can't tell you, how we will handle the security... – Sebi Jun 22 '11 at 12:32
If you do not have heavy wizard-specific views in your application, I doubt you'll actually need to use SWF.
The easiest solution is actually the one Sebi told you - register the Spring EL Resolver and mark your controller classes with appropriate stereotype (most usually, @Controller
) and desired scope. From there on you should be able to get references to Spring-managed beans via manual- or autowiring. And that's all there is to it - no faces-config.xml
bean managment and no "double IoC" overhead. Once it's in Spring context, the managed controller is dereferenced easily from facelet via #{}
EL-notation.
For example:
TestController.java:
@Controller("myController")
@Scope("request")
public class TestController {
@Autowired
private SomeSpringManagedBean someBean;
private String someViewProperty;
public String getSomeViewProperty() {
return someViewProperty;
}
public void setSomeViewProperty(String arg) {
this.someViewProperty = arg;
}
......
}
TestView.jspx:
<p:inputText value="#{myController.someViewProperty}" />
We've lost about 2 weeks trying to tie in SWF together with JSF 1.2 - only to discover that once we actually got it working with the latest version of the IceFaces that support JSF 1.2, the IceFaces had a feature/bug so nasty that it simply wouldn't render the view and had gotten stuck in Phase 5 without throwing any exception or reporting anything useful (the issue became fixed in a 1.8.2-GA version of IceFaces that isn't obtainable without purchasing the license).
EDIT: I noticed basically a similar SO-thread here.
-
Thanks, very intresting. Can I bind a simple "bean" and not a @Controller ? – AgostinoX Jun 22 '11 at 15:13
-
I am not sure that I understand the question - if you need to access a Spring-managed bean from controller, you do so via `@Autowired` or any other preferred way (as shown in my answer). If you're asking whether you can access a non-managed class from view, I don't think so unless you mean to intermix JSF IoC and Spring container - and I can't imagine why would you. At any rate, I would say the best way to expose model values to view is via controller so why would you access non-managed beans from view at all? – quantum Jun 22 '11 at 15:26