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

简介:

 

流控制文件很简单,就是根元素是<view>,然后用<view-state>来代表一个一个的页面,用<transition>来代表从一个状态到另外一个状态的跳转,如果有动作要执行就会加在其中。

对于一个普通的java工程师,一般不需要超过1小时就可以熟知这个文件的编写方法,可查阅相关文档。

对于我们的flow,大体上如下所示:

 

因为图片实在太长,所以我没办法吧整个图片都截下来,这里只截取部分,对于flow定义的xml文件,我完整列在这里,可以供读者参考:

 


  
  
  1. <?xml version="1.0" encoding="UTF-8"?> 
  2. <flow xmlns="http://www.springframework.org/schema/webflow" 
  3.       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  4.       xsi:schemaLocation="http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd"> 
  5.      
  6.      
  7.     <!-- initialize all the variables in the flowScope --> 
  8.     <on-start> 
  9.         <evaluate expression="envProvisionInitService.initialize(flowRequestContext)" /> 
  10.          
  11.         <!-- initialize the flowScope variable:gridList to render the grid list --> 
  12.         <!-- <evaluate expression="aerEnvGridService.listAppEnvRequests()" 
  13.                    result="flowScope.gridListInfoJSONData" /> 
  14.          -->            
  15.         <!--  initialize the flowScope variable: availableServices to be used in hostvip info --> 
  16.         <evaluate expression="defineHostVipService.listAvailableServices()" 
  17.                    result="flowScope.availableServicesInfoJSONData" /> 
  18.                     
  19.         <set name="flowScope.isViewAction" value="false" type="boolean" /> 
  20.                     
  21.     </on-start> 
  22.      
  23.     <view-state id="aerEnvList" > 
  24.      
  25.         <on-render> 
  26.           <evaluate expression="aerEnvGridService.listAppEnvRequests()" result="flowScope.gridListInfoJSONData" /> 
  27.         </on-render> 
  28.          
  29.         <transition on="add" to="defineApp" /> 
  30.         <transition on="confirm" to="aerRequestConfirm" > 
  31.             <!-- fetch the data from web service and ready for populating data --> 
  32.             <evaluate expression="aerEnvGridService.listEnvProvisionInfoByRequestId(requestParameters.requestId,flowRequestContext)"/> 
  33.             <set name="flowScope.isViewAction" value="true" type="boolean" /> 
  34.             <set name="flowScope.requestId" value="requestParameters.requestId" type="string"/> 
  35.         </transition> 
  36.         <transition on="approve" to="aerEnvList"> 
  37.             <evaluate expression="adminService.approve(requestParameters.requestId)" /> 
  38.         </transition> 
  39.         <transition on="close" to="aerEnvList"> 
  40.             <evaluate expression="adminService.close(requestParameters.requestId)" /> 
  41.         </transition> 
  42.         <transition on="reject" to="aerEnvList"> 
  43.             <evaluate expression="adminService.reject(requestParameters.requestId)" /> 
  44.         </transition> 
  45.         <transition on="cmdb" to="aerEnvList"> 
  46.             <evaluate expression="adminService.cmdb(requestParameters.requestId)" /> 
  47.         </transition> 
  48.     </view-state> 
  49.  
  50.     <view-state id="defineApp" >          
  51.      
  52.         <transition on="next" to="defineProject"> 
  53.           <evaluate expression="defineAppService.createAppInfo(requestParameters.appInfoJSONData)" 
  54.                    result="flowScope.appInfo"  /> 
  55.           <set name="flowScope.appInfoJSONData" value="requestParameters.appInfoJSONData" type="string"/> 
  56.           <set name="flowScope.hasAppInfoData" value="true" type="boolean"/> 
  57.         </transition> 
  58.         <transition on="cancel" to="aerEnvList" > 
  59.             <evaluate expression="defineAppService.removeAppInfo(flowRequestContext)" /> 
  60.             <evaluate expression="defineProjectService.removeProjectInfo(flowRequestContext)" /> 
  61.             <evaluate expression="defineHostVipService.removeHostVipInfo(flowRequestContext)" /> 
  62.             <evaluate expression="defineDBSrvService.removeDBServiceInfo(flowRequestContext)"/> 
  63.         </transition> 
  64.     </view-state> 
  65.      
  66.     <view-state id="defineProject"> 
  67.         <transition on="previous" to="defineApp"/> 
  68.          
  69.         <transition on="next" to="defineHostVip">      
  70.             <evaluate expression="defineProjectService.createProjectInfo(requestParameters.projectInfoJSONData)" 
  71.                       result="flowScope.projectInfo"  /> 
  72.             <set name="flowScope.projectInfoJSONData" value="requestParameters.projectInfoJSONData" type="string"/> 
  73.             <set name="flowScope.hasProjectInfoData" value="true" type="boolean"/> 
  74.         </transition> 
  75.         <transition on="cancel" to="aerEnvList"> 
  76.             <evaluate expression="defineAppService.removeAppInfo(flowRequestContext)" /> 
  77.             <evaluate expression="defineProjectService.removeProjectInfo(flowRequestContext)" /> 
  78.             <evaluate expression="defineHostVipService.removeHostVipInfo(flowRequestContext)" /> 
  79.             <evaluate expression="defineDBSrvService.removeDBServiceInfo(flowRequestContext)"/> 
  80.         </transition> 
  81.     </view-state> 
  82.      
  83.     <view-state id="defineHostVip"> 
  84.         <transition on="previous" to="defineProject"/> 
  85.  
  86.         <transition on="next" to="defineDBService"> 
  87.             <evaluate expression="defineHostVipService.createHostVipInfo(requestParameters.hostVipInfoJSONData, flowRequestContext)" 
  88.                       result="flowScope.hostVipInfo"  /> 
  89.             <set name="flowScope.hostVipInfoJSONData" value="requestParameters.hostVipInfoJSONData" type="string"/> 
  90.             <!-- additional set one field to pass the service list to next page(defineDBService.jsp) --> 
  91.             <set name="flowScope.hasHostVipInfoData" value="true" type="boolean"/> 
  92.             <set name="flowScope.services" value="requestParameters.services" type="string" /> 
  93.         </transition> 
  94.         <transition on="cancel" to="aerEnvList"> 
  95.             <evaluate expression="defineAppService.removeAppInfo(flowRequestContext)" /> 
  96.             <evaluate expression="defineProjectService.removeProjectInfo(flowRequestContext)" /> 
  97.             <evaluate expression="defineHostVipService.removeHostVipInfo(flowRequestContext)" /> 
  98.             <evaluate expression="defineDBSrvService.removeDBServiceInfo(flowRequestContext)"/> 
  99.         </transition> 
  100.     </view-state> 
  101.      
  102.     <view-state id="defineDBService"> 
  103.         <transition on="previous" to="defineHostVip"/> 
  104.      
  105.         <transition on="next" to="aerRequestConfirm"> 
  106.             <evaluate expression="defineDBSrvService.createDBServiceInfo(requestParameters.dbServiceInfoJSONData, flowRequestContext)" 
  107.                       result="flowScope.dbServiceInfo"  /> 
  108.             <set name="flowScope.dbServiceInfoJSONData" value="requestParameters.dbServiceInfoJSONData" type="string"/> 
  109.             <set name="flowScope.hasDbServiceInfoData" value="true" type="boolean"/> 
  110.             <set name="flowScope.isSubmitted" value="false" type="boolean"/> 
  111.             <set name="flowScope.isViewAction" value="false" type="boolean" /> 
  112.         </transition> 
  113.         <transition on="cancel" to="aerEnvList"> 
  114.             <evaluate expression="defineAppService.removeAppInfo(flowRequestContext)" /> 
  115.             <evaluate expression="defineProjectService.removeProjectInfo(flowRequestContext)" /> 
  116.             <evaluate expression="defineHostVipService.removeHostVipInfo(flowRequestContext)" /> 
  117.             <evaluate expression="defineDBSrvService.removeDBServiceInfo(flowRequestContext)"/> 
  118.         </transition> 
  119.     </view-state> 
  120.      
  121.     <view-state id="aerRequestConfirm"> 
  122.         <transition on="previous" to="defineDBService"/> 
  123.         <transition on="submit" to="aerRequestSummary">       
  124.             <evaluate expression="envProvisionRequestService.submitEnvProvisionRequest(flowRequestContext)" 
  125.                       result="flowScope.submitResult"  /> 
  126.         </transition> 
  127.          
  128.         <!--  
  129.         <transition on="submit" to="aerRequestSummary"/> 
  130.         --> 
  131.         <transition on="cancel" to="aerEnvList"> 
  132.             <evaluate expression="defineAppService.removeAppInfo(flowRequestContext)" /> 
  133.             <evaluate expression="defineProjectService.removeProjectInfo(flowRequestContext)" /> 
  134.             <evaluate expression="defineHostVipService.removeHostVipInfo(flowRequestContext)" /> 
  135.             <evaluate expression="defineDBSrvService.removeDBServiceInfo(flowRequestContext)"/> 
  136.         </transition> 
  137.          
  138.         <transition on="adminSubmit" to="aerRequestSummary">          
  139.             <evaluate expression="envProvisionRequestService.updateEnvProvisionRequest(flowRequestContext)" 
  140.                       result="flowScope.submitResult"  /> 
  141.             <set name="flowScope.isViewAction" value="false" type="boolean" /> 
  142.  
  143.         </transition> 
  144.          
  145.         <!--  
  146.         <transition on="submit" to="aerRequestSummary"/> 
  147.         --> 
  148.         <transition on="adminCancel" to="aerEnvList"> 
  149.             <evaluate expression="defineAppService.removeAppInfo(flowRequestContext)" /> 
  150.             <evaluate expression="defineProjectService.removeProjectInfo(flowRequestContext)" /> 
  151.             <evaluate expression="defineHostVipService.removeHostVipInfo(flowRequestContext)" /> 
  152.             <evaluate expression="defineDBSrvService.removeDBServiceInfo(flowRequestContext)"/> 
  153.             <set name="flowScope.isViewAction" value="false" type="boolean" /> 
  154.         </transition> 
  155.          
  156.          
  157.         <transition on="noAdminOK" to="aerEnvList"> 
  158.             <evaluate expression="defineAppService.removeAppInfo(flowRequestContext)" /> 
  159.             <evaluate expression="defineProjectService.removeProjectInfo(flowRequestContext)" /> 
  160.             <evaluate expression="defineHostVipService.removeHostVipInfo(flowRequestContext)" /> 
  161.             <evaluate expression="defineDBSrvService.removeDBServiceInfo(flowRequestContext)"/> 
  162.             <set name="flowScope.isViewAction" value="false" type="boolean" /> 
  163.         </transition> 
  164.          
  165.          
  166.          
  167.         <!--add 4 event to distingush different partin the request confirmation page--> 
  168.         <transition on="editApplicationInfo" to="defineApp"/> 
  169.         <transition on="editProjectInfo"  to="defineProject"/> 
  170.         <transition on="editHostVipInfo"  to="defineHostVip"/> 
  171.         <transition on="editDBServiceInfo"  to="defineDBService"/> 
  172.     </view-state> 
  173.      
  174.     <view-state id="aerRequestSummary"> 
  175.         <transition on="ok" to="aerEnvList"> 
  176.             <evaluate expression="defineAppService.removeAppInfo(flowRequestContext)" /> 
  177.             <evaluate expression="defineProjectService.removeProjectInfo(flowRequestContext)" /> 
  178.             <evaluate expression="defineHostVipService.removeHostVipInfo(flowRequestContext)" /> 
  179.             <evaluate expression="defineDBSrvService.removeDBServiceInfo(flowRequestContext)"/> 
  180.         </transition> 
  181.     </view-state> 
  182.      
  183.     <end-state id="finish"/> 
  184.              
  185. </flow> 

这里,因为我们在这系列的第二篇文章中已经提及到,我们开启了包扫描机制,所以这些Spring的Bean在应用上下文创建的时候就已经实例化了,所以在这个流定义文件中可以轻松的使用这些bean.

 

 其实在做架构的时候,我曾和我们团队其他开发者讨论到为什么我们用spring web flow,其实这种页面跳转我们也可以不用web flow做,最后采用web flow的架构是基于以下几个原因:

众所周知,一般web应用的scope有 request,session,application,因为在很多配置页面上都有数据,并且这些数据都要共享,还比较大(那些传递的vo动辄100+字段)而且业务流程也比较复杂,而且这些数据还是有状态的,所以我们无法放在request scope上,而如果放在session scope上,又会加重系统的内存负担,所以我们需要一种介于request,session范围之间的scope,而spring web flow刚好提供了flow scope来精确的满足我们的需求,所以我们使用spring web flow.





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

目录
相关文章
|
前端开发 Java 测试技术
微服务——SpringBoot使用归纳——Spring Boot中的MVC支持——@RequestParam
本文介绍了 `@RequestParam` 注解的使用方法及其与 `@PathVariable` 的区别。`@RequestParam` 用于从请求中获取参数值(如 GET 请求的 URL 参数或 POST 请求的表单数据),而 `@PathVariable` 用于从 URL 模板中提取参数。文章通过示例代码详细说明了 `@RequestParam` 的常用属性,如 `required` 和 `defaultValue`,并展示了如何用实体类封装大量表单参数以简化处理流程。最后,结合 Postman 测试工具验证了接口的功能。
1038 0
微服务——SpringBoot使用归纳——Spring Boot中的MVC支持——@RequestParam
|
JSON 前端开发 Java
微服务——SpringBoot使用归纳——Spring Boot中的MVC支持——@RequestBody
`@RequestBody` 是 Spring 框架中的注解,用于将 HTTP 请求体中的 JSON 数据自动映射为 Java 对象。例如,前端通过 POST 请求发送包含 `username` 和 `password` 的 JSON 数据,后端可通过带有 `@RequestBody` 注解的方法参数接收并处理。此注解适用于传递复杂对象的场景,简化了数据解析过程。与表单提交不同,它主要用于接收 JSON 格式的实体数据。
1723 0
|
12月前
|
缓存 安全 Java
《深入理解Spring》过滤器(Filter)——Web请求的第一道防线
Servlet过滤器是Java Web核心组件,可在请求进入容器时进行预处理与响应后处理,适用于日志、认证、安全、跨域等全局性功能,具有比Spring拦截器更早的执行时机和更广的覆盖范围。
|
12月前
|
前端开发 Java 微服务
《深入理解Spring》:Spring、Spring MVC与Spring Boot的深度解析
Spring Framework是Java生态的基石,提供IoC、AOP等核心功能;Spring MVC基于其构建,实现Web层MVC架构;Spring Boot则通过自动配置和内嵌服务器,极大简化了开发与部署。三者层层演进,Spring Boot并非替代,而是对前者的高效封装与增强,适用于微服务与快速开发,而深入理解Spring Framework有助于更好驾驭整体技术栈。
|
存储 安全 Java
如何在 Spring Web 应用程序中使用 @SessionScope 和 @RequestScope
Spring框架中的`@SessionScope`和`@RequestScope`注解用于管理Web应用中的状态。`@SessionScope`绑定HTTP会话生命周期,适用于用户特定数据,如购物车;`@RequestScope`限定于单个请求,适合无状态、线程安全的操作,如日志记录。合理选择作用域能提升应用性能与可维护性。
486 1
|
前端开发 Java 开发者
MVC 架构模式技术详解与实践
本文档旨在全面解析软件工程中经典且至关重要的 MVC(Model-View-Controller) 架构模式。内容将深入探讨 MVC 的核心思想、三大组件的职责与交互关系、其优势与劣势,并重点分析其在现代 Web 开发中的具体实现,特别是以 Spring MVC 框架为例,详解其请求处理流程、核心组件及基本开发实践。通过本文档,读者将能够深刻理解 MVC 的设计哲学,并掌握基于该模式进行 Web 应用开发的能力。
2020 1
|
存储 NoSQL Java
探索Spring Boot的函数式Web应用开发
通过这种方式,开发者能以声明式和函数式的编程习惯,构建高效、易测试、并发友好的Web应用,同时也能以较小的学习曲线迅速上手,因为这些概念与Spring Framework其他部分保持一致性。在设计和编码过程中,保持代码的简洁性和高内聚性,有助于维持项目的可管理性,也便于其他开发者阅读和理解。
324 0
|
前端开发 Java API
Spring Cloud Gateway Server Web MVC报错“Unsupported transfer encoding: chunked”解决
本文解析了Spring Cloud Gateway中出现“Unsupported transfer encoding: chunked”错误的原因,指出该问题源于Feign依赖的HTTP客户端与服务端的`chunked`传输编码不兼容,并提供了具体的解决方案。通过规范Feign客户端接口的返回类型,可有效避免该异常,提升系统兼容性与稳定性。
965 0
|
SQL Java 数据库连接
Spring、SpringMVC 与 MyBatis 核心知识点解析
我梳理的这些内容,涵盖了 Spring、SpringMVC 和 MyBatis 的核心知识点。 在 Spring 中,我了解到 IOC 是控制反转,把对象控制权交容器;DI 是依赖注入,有三种实现方式。Bean 有五种作用域,单例 bean 的线程安全问题及自动装配方式也清晰了。事务基于数据库和 AOP,有失效场景和七种传播行为。AOP 是面向切面编程,动态代理有 JDK 和 CGLIB 两种。 SpringMVC 的 11 步执行流程我烂熟于心,还有那些常用注解的用法。 MyBatis 里,#{} 和 ${} 的区别很关键,获取主键、处理字段与属性名不匹配的方法也掌握了。多表查询、动态
430 0
|
JSON 前端开发 Java
第05课:Spring Boot中的MVC支持
第05课:Spring Boot中的MVC支持
507 0

推荐镜像

更多