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

OAF_架构MVC系列4 - Control的概述(概念)的更多相关文章

  1. OAF_架构MVC系列3 - View的概述(概念)

    2014-06-18 Created By BaoXinjian

  2. OAF_架构MVC系列2 - Model的概述(概念)

    2014-06-22 Created By BaoXinjian

  3. OAF_架构MVC系列1 - MVC的概述(概念)

     2015-04-03 Created By BaoXinjian

  4. mvc项目架构分享系列之架构搭建初步

    mvc项目架构分享系列之架构搭建初步 Contents 系列一[架构概览] 0.项目简介 1.项目解决方案分层方案 2.所用到的技术 3.项目引用关系 系列二[架构搭建初步] 4.项目架构各部分解析 ...

  5. Asp.net mvc项目架构分享系列之架构概览

    Asp.net mvc项目架构分享系列之架构概览 Contents 系列一[架构概览] 0.项目简介 1.项目解决方案分层方案 2.所用到的技术 3.项目引用关系 系列二[架构搭建初步] 4.项目架构 ...

  6. Asp.net mvc项目架构分享系列之架构搭建初步

    copy to:http://www.cnblogs.com/ben121011/p/5014795.html 项目架构各部分解析 Core Models IDAL MSSQLDAL IBLL BLL ...

  7. 【ASP.NET MVC系列】浅谈ASP.NET MVC八大类扩展(上篇)

    lASP.NET MVC系列文章 [01]浅谈Google Chrome浏览器(理论篇) [02]浅谈Google Chrome浏览器(操作篇)(上) [03]浅谈Google Chrome浏览器(操 ...

  8. 【ASP.NET MVC系列】浅谈ASP.NET MVC运行过程

    ASP.NET MVC系列文章 [01]浅谈Google Chrome浏览器(理论篇) [02]浅谈Google Chrome浏览器(操作篇)(上) [03]浅谈Google Chrome浏览器(操作 ...

  9. 【ASP.NET MVC系列】浅谈Google Chrome浏览器(操作篇)(下)

    ASP.NET MVC系列文章 [01]浅谈Google Chrome浏览器(理论篇) [02]浅谈Google Chrome浏览器(操作篇)(上) [03]浅谈Google Chrome浏览器(操作 ...

随机推荐

  1. Unable to get valid context for root

    登陆时报以下错误Unable to get valid context for rootLast login: Wed Jul 24 02:06:01 2013 from 10.64.41.3 单机模 ...

  2. scala言语基础学习十

    类型参数 泛型函数 多个参数 使用泛型参数时候,不给类型scala也能自己判断 上边界bounds 下边界bounds 专门用于打包泛型数组

  3. Dwarves (有向图判环)

    Dwarves 时间限制: 1 Sec  内存限制: 64 MB提交: 14  解决: 4[提交][状态][讨论版] 题目描述 Once upon a time, there arose a huge ...

  4. 越狱Season 1-Episode 17: J-Cat

    Season 1, Episode 17: J-Cat -Pope: Hey, that's looking good. 嗨,看起来真棒 You're making some real progres ...

  5. 关于正则表达式处理textarea里的换行

    将textarea里的内容存入数据库时,会自动将回车换行符过滤成空格,也会将多个空格转换成一个空格,即:将\n等换成 “  ”存入数据库 因此为了将内容从数据库中按照原来格式读出写入到html 就必须 ...

  6. java Pattern

    public class Test{ //匹配替换掉order by之后的字符串 public static void main(String[] args) { Pattern pattern = ...

  7. 无shell情况下的mysql远程mof提权利用方法详解

    扫到一个站的注入<ignore_js_op> 在havij中得到mysql数据库中mysql库保存的数据库密码:<ignore_js_op> 有时候发现1.15版的还是最好用, ...

  8. Linux 下 Lua 与 LuaSQL 模块安装

    相关说明: Lua最近在Nginx的web服务器上挺火的, 它的高效让更多开发喜欢上它, 本文讲述Lua与LuaSQL的安装. 在上几篇mysql-proxy的安装中有提到和操作过. 操作系统: Li ...

  9. ARTICLES

    https://blogs.msdn.microsoft.com/tess/2005/12/20/things-to-ignore-when-debugging-an-asp-net-hang/ ht ...

  10. 5分钟实现Android中更换头像功能

    写在前面:更换头像这个功能在用户界面几乎是100%出现的.通过拍摄照片或者调用图库中的图片,并且进行剪裁,来进行头像的设置.功能相关截图如下: 下面我们直接看看完整代码吧: 1 2 3 4 5 6 7 ...