MESSL(maven + extjs + spring portlet mvc + spring web flow + liferay )整合架构 4

 上篇文章讲到了我们定义portlet应用级别的spring 配置文件为/WEB-INF/config/envprovisioning-config.xml ,下面我们来看下这个spring配置文件内容:

 

 
  
  1. <?xml version="1.0" encoding="UTF-8"?> 
  2. <beans xmlns="http://www.springframework.org/schema/beans" 
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  4.        xmlns:webflow="http://www.springframework.org/schema/webflow-config" 
  5.        xsi:schemaLocation=" 
  6.            http://www.springframework.org/schema/beans 
  7.            http://www.springframework.org/schema/beans/spring-beans.xsd 
  8.            http://www.springframework.org/schema/webflow-config 
  9.            http://www.springframework.org/schema/webflow-config/spring-webflow-config.xsd"> 
  10.  
  11.     <!-- Maps portlet modes to handlers -->  
  12.     <bean id="portletModeHandlerMapping" class="org.springframework.web.portlet.handler.PortletModeHandlerMapping"> 
  13.         <property name="portletModeMap"> 
  14.             <map> 
  15.                 <entry key="view"> 
  16.                     <bean class="com.walmart.platform.envprovisioning.handlers.EnvProvisionFlowHandler" /> 
  17.                 </entry> 
  18.             </map> 
  19.         </property> 
  20.         <property name="interceptors">   
  21.             <list>   
  22.                 <ref bean="envprovisionhandlerinterceptor"/> 
  23.             </list>   
  24.         </property> 
  25.     </bean> 
  26.     <!-- add interceptor to get user and privilege --> 
  27.     <bean id="envprovisionhandlerinterceptor" class="com.walmart.platform.envprovisioning.interceptors.EnvProvisionHandlerInterceptor"/> 
  28.  
  29.     <!-- Maps logical view names selected by the url filename controller to .jsp view templates within the /WEB-INF directory -->    
  30.     <bean id="internalJspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
  31.         <property name="prefix" value="/WEB-INF/" /> 
  32.         <property name="suffix" value=".jsp" /> 
  33.     </bean> 
  34.      
  35.     <!-- Enables FlowHandlers --> 
  36.     <bean class="org.springframework.webflow.mvc.portlet.FlowHandlerAdapter"> 
  37.         <property name="flowExecutor" ref="flowExecutor"/> 
  38.     </bean> 
  39.  
  40.     <!-- Executes flows: the central entry point into the Spring Web Flow system --> 
  41.     <webflow:flow-executor id="flowExecutor" /> 
  42.      
  43.     <!-- The registry of executable flow definitions --> 
  44.     <webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices"> 
  45.         <webflow:flow-location path="/WEB-INF/flows/envprovision/envprovision.xml" /> 
  46.     </webflow:flow-registry>     
  47.  
  48.     <!-- Plugs in Spring's JSR-303 validator adapter --> 
  49.     <webflow:flow-builder-services id="flowBuilderServices" development="true" validator="validator" /> 
  50.          
  51.     <!-- Bootstraps JSR-303 validation and exposes it through Spring's Validator interface --> 
  52.     <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/> 
  53.  
  54.   
  55. </beans> 

这个文件更多的是对spring web flow进行了配置,容我细细道来:

首先在第15-17行,我们portletModeMap,对view Mode ,我们扔给了EnvProvisionFlowHandler类,这就表明,我们让在spring portlet mvc中,我们用EnvProvisionFlowHandler类充当portlet view mode的处理类。 而这个EnvProvisionFlowHandler类是从AbstractFlowHandler继承来的, 所以我们理所当然的使用了Spring WebFlow 的FlowHandler来充当处理器:

 
  
  1. /** 
  2.  * this class is the flowHandler 
  3.  * When application deployed to container ,the container will read the envprovisioning-config.xml 
  4.  * then it will get the instance for this flowHandler ,and the getFlowId() method will identify which flow it will 
  5.  * enter into. 
  6.  *  
  7.  *@author cwang58 
  8.  *@created date: Feb 18, 2013 
  9.  */ 
  10. public class EnvProvisionFlowHandler extends AbstractFlowHandler { 
  11.  
  12.     /** 
  13.      * the flowId which identifies the flow which will be handled by this flowHandler 
  14.      * since here it returns envprovision ,so it will go to the flow which is describled by flow 
  15.      * definition file "envprovision.xml" 
  16.      */ 
  17.     public String getFlowId() { 
  18.     return "envprovision"
  19.     } 
  20.  
  21.      
  22.  
  23.  

这个类我们只需要实现一个方法,就是getFlowId(),他用来表示,我们用什么web flow来充当view 模式的处理器, 在这里,返回的是envprovision,所以我们用这个流来充当view模式处理器。

 

既然得到了flowId之后,我们就去找对应的 web flow.首先必须明白,flow的执行者是由FlowHandlerAdaptor来完成的,所以我们在36-38行,我们定义了一个属性叫flowExecutor来专门用于执行flow.

而flowExecutor会专门使用一个flowRegistry Bean来执行定义在/WEB-INF/flows 下的基于XML的流跳转定义文件,所以我们又在44-46行中显式的给出了流定义XML文件,因为(Convention over Configuration),默认的流定义文件的文件名就是flowId,所以我们很容易找到了前文中返回的envprovision的流Id就对应这里的envprovision.xml文件,所以当portlet view 模式时,就会把控制权交给Spring Web Flow,然后用envprovision.xml中定义的流跳转逻辑来处理view 模式,就这么简单。

 

下篇文章我们来探讨这个流控制文件。





本文转自 charles_wang888 51CTO博客,原文链接:http://blog.51cto.com/supercharles888/1138849,如需转载请自行联系原作者

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值