OAF_架构MVC系列4 - Control的概述(概念)

简介: 2014-06-18 Created By BaoXinjian 一、摘要 Control层位于Model层和View层的中间,连接了Model层和View层, 主要存在两个功能 操作/初始化UI和数据 接受和处理页面上的用户的各种事件,并进行分发 本文的基本结构 Design...

2014-06-18 Created By BaoXinjian

一、摘要


Control层位于Model层和View层的中间,连接了Model层和View层,

主要存在两个功能

  • 操作/初始化UI和数据
  • 接受和处理页面上的用户的各种事件,并进行分发

本文的基本结构

  • Designand Create an OA Controller - 基本概念和建立
  • Handling an HTTP GET - 如何处理HTTP GET请求
    • Data层面 - 进行初始化
    • WebBean层面
      • WebBean层面 - 动态修改WebBean的属性
      • WebBean层面 - 动态创建WebBean
  • Handing an HTTP POST - 如何处理HTTP POST请求
    • processFormData( )
    • processFormRequest( )
  • Model Interaction - Contorl层和Model层的整合
    • 在CO中通过pageContext.getRootApplicationModule()获取AM
    • 查询 - 在CO中调用AM的Search方法
    • 新增 - 在CO中调用AM的Create方法
    • 删除 - 在CO中调用AM的Delete方法
    • 提交 - 在CO中调用AM的Commit方法

OAF构成原件中Contorller的位置


 

二、具体解析


1. Designand Create an OA Controller - 基本概念和建立

选中PageRN,右击Set New Controller or Edit Contorller

系统会自动产生HTTP Get方法(processRequset)和HTTP Post方法(processFormRequest)

 

2. Handling an HTTP GET - 如何处理HTTP GET请求

2.1 修改WebBean的属性

比如动态修改TableText

processRequest(OAPageContext pageContext, OAWebBean webBean)
{
  // Always call this before adding your own code.  super.processRequest(pageContext, webBean);
 
  OATableBean table = (OATableBean)webBean.findIndexedChildRecursive("OrdersTable");
  if (table == null)
  {
     MessageToken[] tokens = { new MessageToken("OBJECT_NAME", "OrdersTable")};
     throw new OAException("ICX", "FWK_TBX_OBJECT_NOT_FOUND", tokens);
  }
   
  // Set the purchase-order specific "control bar" select text:
  // "Select Purchase Order(s) and..."
  String selectPOText = pageContext.getMessage("ICX", "FWK_TBX_T_SELECT_PO", null);
  table.setTableSelectionText(selectPOText);
}

2.2 创建WebBean

比如动态新增Table Row

OATableLayoutBean tableLayout = (OATableLayoutBean)findIndexedChildRecursive("tableLayout");
// Create a row layout and give it the unique ID "topRow"
OARowLayoutBean row = (OARowLayoutBean)createWebBean(pageContext,
                                                                                           OAWebBeanConstants.ROW_LAYOUT_BEAN,
                                                                                           null, // no need to specify a data type
                                                                                          "topRow");
// Create a row layout and give it the unique ID "bottomRow"
OARowLayoutBean anotherRow = (OARowLayoutBean)createWebBean(pageContext,
                                                                                                       OAWebBeanConstants.ROW_LAYOUT_BEAN,
                                                                                                       null, // no need to specify a data type
                                                                                                       "bottomRow");
// Always check to see if a web bean exists.
if (tableLayout != null)
{
   // Add the two row layout beans to the table so the "topRow" renders above
   // the "bottomRow"
   tableLayout.addIndexedChild(row);
   tableLayout.addIndexedChild(anotherRow);
}

3. Handing an HTTP POST - 如何处理HTTP POST请求

public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{
   // Always call this before adding your code
   super.processFormRequest(pageContext, webBean);
   // Pressing the Go button causes the search to be executed.   If (pageContext.getParameter("Go") != null)
   {
     String orderNumber = pageContext.getParameter("SearchOrder");
     String created = pageContext.getParameter("Created");
     String showMyOrders = pageContext.getParameter("MyOrders");
     OAApplicationModule am = pageContext.getApplicationModule(webBean);
     // All parameters passed using invokeMethod() must be serializable.
     Serializable[] parameters = { orderNumber, created, showMyOrders };
     am.invokeMethod("search", parameters);
     // Now forward back to this page so we can implement UI changes as a
     // consequence of the query in processRequest(). NEVER make UI changes in
     // processFormRequest().
     pageContext.setForwardURLToCurrentPage(null, // no parameters to pass
                                            true, // retain the AM
                                            OAWebBeanConstants.ADD_BREAD_CRUMB_NO,
                                            OAWebBeanConstants.IGNORE_MESSAGES);   
  }
} // end processFormRequest();

4. Model Interaction - Contorl层和Model层的整合

4.1 在Am中调用Search方法,具体如何Search则定义在AM中

processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{
  // Check to see if the "Go" button was pressed...
  if (pageContext.getParameter("gButton") != null)
  {
    // Get the search criteria
    String orderNumber = pageContext.getParameter("SearchOrder");
    String created = pageContext.getParameter("Created");
    String showMyOrders = pageContext.getParameter("MyOrders");
    OAApplicationModule am = pageContext.getApplicationModule(webBean);
    // All parameters passed using invokeMethod() must be serializable.    Serializable[] parameters = { orderNumber, created, showMyOrders };
    am.invokeMethod("search", parameters);
  }
}

4.2 在Am中调用Create方法,具体如何Create则定义在AM中

processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{
  OAApplicationModule am = pageContext.getApplicationModule(webBean);
  am.invokeMethod("create", null);
}

4.3 在Am中调用Delete方法,具体如何Delete则定义在AM中

processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{
 if (pageContext.getParameter("DeleteYesButton") != null)
 {
   // User has confirmed that she wants to delete this purchase order.
   // Invoke a method on the AM to set the current row in the VO and
   // call remove() on this row.
   
   String poHeaderId = pageContext.getParameter("poHeaderId");
   Serializable[] parameters = { poHeaderId };
   OAApplicationModule am = pageContext.getApplicationModule(webBean);     am.invokeMethod("delete", parameters);
  }

4.4 在Am中调用Commit方法,具体如何Commit则定义在AM中

processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{
  if (pageContext.getParameter("Approve") != null)
  {
    OAApplicationModule am = pageContext.getApplicationModule(webBean);
    am.invokeMethod("Apply");
  }
}

 

Thanks and Regards

ERP技术讨论群: 288307890
技术交流,技术讨论,欢迎加入
Technology Blog Created By Oracle ERP - 鲍新建
相关文章
|
人工智能 运维 安全
AI 安全架构概述
AI 安全架构涵盖数据采集、模型训练、推理部署等阶段,确保安全性、隐私与合规。其核心组件包括数据层、模型层、推理层、应用层和运维层,针对数据安全威胁(如数据投毒)、模型窃取、对抗攻击及系统漏洞等风险,提出数据加密、对抗训练、联邦学习等防御策略,并强调开发前、开发中和部署后的最佳实践,以降低 AI 解决方案的安全风险。
1808 14
|
资源调度 监控 调度
基于SCA的软件无线电系统的概念与架构
软件通信体系架构(SCA)是基于软件定义无线电(SDR)思想构建的开放式、标准化和模块化平台,旨在通过软件实现通信功能的灵活配置。SCA起源于美军为解决“信息烟囱”问题而推出的联合战术无线电系统(JTRS),其核心目标是提升多军种联合作战通信能力。 上海介方信息公司的OpenSCA操作环境严格遵循SCA4.1/SRTF标准,支持高集成、嵌入式等场景,适用于军用通信、雷达等领域。 SCA体系包括目标平台资源层(TRL)、环境抽象层(EAL)、SRTF操作环境(OE)及应用层(AL)。其中,SRTF操作环境包含操作系统、运行时环境(RTE)和核心框架(CF),提供波形管理、资源调度等功能。
|
Java Linux 虚拟化
【Docker】(1)Docker的概述与架构,手把手带你安装Docker,云原生路上不可缺少的一门技术!
1. Docker简介 1.1 Docker是什么 为什么docker会出现? 假定您在开发一款平台项目,您的开发环境具有特定的配置。其他开发人员身处的环境配置也各有不同。 您正在开发的应用依赖于您当前的配置且还要依赖于某些配置文件。 您的企业还拥有标准化的测试和生产环境,且具有自身的配置和一系列支持文件。 **要求:**希望尽可能多在本地模拟这些环境而不产生重新创建服务器环境的开销 问题: 要如何确保应用能够在这些环境中运行和通过质量检测? 在部署过程中不出现令人头疼的版本、配置问题 无需重新编写代码和进行故障修复
934 2
|
存储 前端开发 调度
Flux 与传统的 MVC 架构模式区别
Flux是一种用于构建用户界面的架构模式,与传统的MVC架构不同,它采用单向数据流,通过Dispatcher统一管理数据的分发,Store负责存储数据和业务逻辑,View只负责展示数据,使得应用状态更加可预测和易于维护。
|
存储 分布式计算 大数据
大数据-169 Elasticsearch 索引使用 与 架构概念 增删改查
大数据-169 Elasticsearch 索引使用 与 架构概念 增删改查
455 3
|
前端开发 Java 开发者
MVC 架构模式技术详解与实践
本文档旨在全面解析软件工程中经典且至关重要的 MVC(Model-View-Controller) 架构模式。内容将深入探讨 MVC 的核心思想、三大组件的职责与交互关系、其优势与劣势,并重点分析其在现代 Web 开发中的具体实现,特别是以 Spring MVC 框架为例,详解其请求处理流程、核心组件及基本开发实践。通过本文档,读者将能够深刻理解 MVC 的设计哲学,并掌握基于该模式进行 Web 应用开发的能力。
2111 1
|
存储 分布式计算 API
大数据-107 Flink 基本概述 适用场景 框架特点 核心组成 生态发展 处理模型 组件架构
大数据-107 Flink 基本概述 适用场景 框架特点 核心组成 生态发展 处理模型 组件架构
1185 0
|
供应链 监控 安全
网络安全中的零信任架构:从概念到部署
网络安全中的零信任架构:从概念到部署
1614 75
|
人工智能 前端开发 Java
DDD四层架构和MVC三层架构的个人理解和学习笔记
领域驱动设计(DDD)是一种以业务为核心的设计方法,与传统MVC架构不同,DDD将业务逻辑拆分为应用层和领域层,更关注业务领域而非数据库设计。其四层架构包括:Interface(接口层)、Application(应用层)、Domain(领域层)和Infrastructure(基础层)。各层职责分明,避免跨层调用,确保业务逻辑清晰。代码实现中,通过DTO、Entity、DO等对象的转换,结合ProtoBuf协议,完成请求与响应的处理流程。为提高复用性,实际项目中可增加Common层存放公共依赖。DDD强调从业务出发设计软件,适应复杂业务场景,是微服务架构的重要设计思想。