开发者

Using Spring @Value systemProperties into Managed Bean

I want inject systemProperties into a JSF Managed Bean (jsf 1.2 ).

The only way that this can be done is if I either use a managed property or create a systemProperties bean and inject that into the managed bean I want, correct? I can't use @Value like; It has to be a spring bean in order for me to do that.

#{systemProperties['databaseName']}

#{systemPropertie开发者_运维知识库s.databaseName}

Managed Property

    <managed-bean>
    <managed-bean-name>fooUI</managed-bean-name>
    <managed-bean-class>test.foo</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    <managed-property>
        <property-name>systemPropertyExample</property-name>
        <value>#{systemProperties['systemPropertyExample']}</value>
    </managed-property>  
</managed-bean>  


JSF managed beans can be spring managed. You just have to configure a spring-specific <el-resolver> in faces-config.xml:

<el-resolver>
     org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver> 

It will resolve managed beans within the spring context (of course, you need a ContextLoaderListener in web.xml that bootstraps spring, but I assume you have that). Then you can use @Value, dependency injection, etc, in your jsf beans.

The only difference is that you will be defining them with @Controller @Scope("request") rather than with xml.


You can annotate the JSF Bean with @Configurable, then you can use it like a spring bean. (Attention this requires the use of AspectJ)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜