waterye

Spring集成JSF

JSF似乎越来越热, Oracle也将ADF贡献给Apache, 作为MyFaces的subprojcet Cherokee.

Spring集成JSF的最简单方式是使用DelegatingVariableResolver类
1. web.xml

 1<context-param>
 2        <param-name>javax.faces.CONFIG_FILES</param-name>
 3        <param-value>
 4            /WEB-INF/faces-config.xml
 5        </param-value>
 6    </context-param>
 7
 8    <context-param>
 9        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
10        <param-value>client</param-value>
11    </context-param>
12
13    <servlet>
14        <servlet-name>Faces Servlet</servlet-name>
15        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
16        <load-on-startup>1</load-on-startup>
17    </servlet>
18
19    <servlet-mapping>
20        <servlet-name>Faces Servlet</servlet-name>
21        <url-pattern>*.jsf</url-pattern>
22    </servlet-mapping>

2. faces-config.xml

 1<!-- Spring VariableResolver for JSF -->
 2    <application>
 3        <variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>
 4        <locale-config>
 5          <default-locale>zh_CN</default-locale>
 6          <supported-locale>en</supported-locale>
 7          <supported-locale>zh_CN</supported-locale>
 8        </locale-config>
 9        <message-bundle>messages</message-bundle>
10    </application>
11
12    <managed-bean>
13        <managed-bean-name>goodsController</managed-bean-name>
14        <managed-bean-class>web.jsf.GoodsController</managed-bean-class>
15        <managed-bean-scope>request</managed-bean-scope>
16        <!-- inject service -->
17        <managed-property>
18            <property-name>goodsService</property-name>
19            <value>#{goodsService}</value> <!-- inject service -->
20        </managed-property>
21    </managed-bean>

3. GoodsController.java
 1public class GoodsController implements Serializable
 2{
 3    private GoodsService goodsService;
 4
 5    public void setGoodsService(GoodsService goodsService)
 6    {
 7        this.goodsService = goodsService;
 8    }

 9
10    public List getGoodsList() throws Exception
11    {
12        return goodsService.getAll();
13    }

14}

参考: spring-framework-1.2.6/docs/reference/html_single/index.html#jsf
jsf版的appfuse也是不错的参考
sf还有jsf-spring的项目: http://jsf-spring.sourceforge.net/

JSF组件
List of standard JSF components
http://wiki.apache.org/myfaces/JsfComponents

List of custom MyFaces Tomahawk components and extensions
http://wiki.apache.org/myfaces/MyFacesComponents

但感觉navigation-rule的配置好烦, 还有tomahawk的组件用起来不太习惯 (可能是不熟的原因)

posted on 2005-12-15 18:17 waterye 阅读(1147) 评论(0)  编辑  收藏 所属分类: spring


只有注册用户登录后才能发表评论。


网站导航: