随笔 - 170  文章 - 536  trackbacks - 0
<2006年9月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

常用链接

我参与的团队

随笔分类(103)

搜索

  •  

积分与排名

  • 积分 - 410649
  • 排名 - 134

最新评论

阅读排行榜

看到 Shale 的 Spring Integration 文档的介绍原理,其中顺序如下:

When asked to resolve a variable name, the following algorithm is performed:

1.Does a bean with the specified name already exist in some scope (request, session, application)? If so, return it.

2.Is there a standard JavaServer Faces managed bean definition for this variable name? If so, invoke it in the usual way, and return the bean that was created.

3.Is there configuration information for this variable name in the Spring WebApplicationContext for this application? If so, use it to create and configure an instance, and return that instance to the caller.

4.If there is no managed bean or Spring definition for this variable name, return null instead.

这样的话,只要 Spring 可以控制 Bean 的 Scope 的话,就可以把 Managed-Bean 的配置放到 Spring Bean 里来配置,一方面,我们可以省去了 JSF 的 Managed Bean 的配置,另外的话,我们可以对 JSF 的 Backing Bean 使用 AOP 以及 Spring 提供的很多功能。过去在 JSF-Spring 中尝试着去控制 Spring Bean 的 Scope,但是做的并不好,现在 Spring 2.0 给我们提供了这样的能力,经过实验,证明了这样是可行的。

不过如果使用 Spring Bean 以后,会造成使用 Managed Bean 的 JSTL 无法使用,其实 JSTL 本身用起来就时好时坏的,所以影响并不太大了。

整合起来步骤非常的简单:

1. 把 Spring 2.0 的 jar 文件放到 lib 下面,当前使用的是 Spring 2.0 RC3

2. 因为使用的是 Servlet 2.4,所以要在 web.xml 中加入
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>

3. 修改 applicationContext.xml

注释或删掉以下内容:

  <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
  "
http://www.springframework.org/dtd/spring-beans.dtd ">

修改 <beans> 为:

  <beans xmlns=" http://www.springframework.org/schema/beans "
       xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance "
       xmlns:aop="
http://www.springframework.org/schema/aop "
       xsi:schemaLocation="
 
http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd ">

4. 然后就可以按照配置 Spring Bean 的方式来配置 Managed Bean:

    这个是 Request Scope 中的 Bean:
    <bean id="loginBean" class="org.agilejava.icustomer.backingbean.LoginBean"
          scope="request" autowire="byName">
        <aop:scoped-proxy/>
    </bean>

    这个是 Session Scope 中的 Bean:
    <bean id="menuBean" class="org.agilejava.framework.commons.menu.MenuBackingBean"
          scope="session" autowire="byName">
        <aop:scoped-proxy/>
    </bean>

虽然短期来看,配置上会少写了一些,因为 autowire="byName",但是从长远来看,我们可以利用 Spring 的更多功能,比如 AOP 来增强 Backing Bean 的能力,我的第一个设想就是用 AOP 来处理 Backing Bean 中的异常,今后几天我会继续做这方面的实践了。

posted on 2006-09-05 10:16 steady 阅读(3560) 评论(2)  编辑  收藏 所属分类: JSF & Myfaces

FeedBack:
# re: JSF without ManagedBean 2006-09-12 16:19 dzzhu
最近我也在考虑jsf的exception统一处理的问题,jsf没有提供像struts和webwork提供的那些exception定向功能。

http://forum.java.sun.com/thread.jspa?threadID=765655
这篇帖子部分的讨论了解决办法,用servlet filter,定制lifecycle,navigationhandler,ActionListener等,AOP应该也是一种解决方法,MBean的getter我想就不用对应了,考虑对应shale的prerender等几个action就OK了。  回复  更多评论
  
# re: JSF without ManagedBean 2008-02-02 11:47 ghost
实际上我自己是这样实现的,将带有状态数据的类似prototype类型的对象被JSF配置,而类似于singleton的带有操作方法的对象(不依赖于数据)被Spring配置,这样Spring就不会牵涉到WEB层的request,response,session等对象,这样可以保证松耦合  回复  更多评论
  

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


网站导航: