spring faces without spring flow

前端 未结 2 975
暗喜
暗喜 2021-01-17 06:15

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 no

相关标签:
2条回答
  • 2021-01-17 06:33

    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.

    0 讨论(0)
  • 2021-01-17 06:55

    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.

    0 讨论(0)
提交回复
热议问题