首页 > Web开发 > 详细

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

时间:2014-06-28 20:50:59      阅读:710      评论:0      收藏:0      [点我收藏+]

2014-06-18 BaoXinjian

bubuko.com,布布扣一、摘要


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的位置

bubuko.com,布布扣
 

bubuko.com,布布扣二、具体解析


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

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

bubuko.com,布布扣

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

bubuko.com,布布扣

 

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

bubuko.com,布布扣

OAF_OAF架构MVC系列 - Control的概述(概念),布布扣,bubuko.com

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

原文:http://www.cnblogs.com/eastsea/p/3794570.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!