Model-View-Controller 简称MVC. 简单的说就是把数据处理,显示,页面事件及处理过程分离开来,企业应用多数都采用这种方式,多层架构的优缺点不再多言,google一下啥都知道。

在企业应用中我们以SRMSUS 为例。

系统由以下结构组成

 

Controller来处理系统事件及数据过程

Views 是页面/子页面

Page 是带有逻辑过程的页面,之前介绍过

Page Fragments ,例如很多页面需要header及footer,这个东西就是一些代码片断,可以被出入到需要的地方,不用重复编码

MIMES 代表系统需要的一些图片,例如logo等

MVC模式的系统处理程序与之前的介绍的很不相同,它先处理main controller,由main controller调用main view,然后其用户触发的事件再由main controller处理,然后再调用相应的view来展示或者别的动作。

我们一般创建Controller (就是一个类)的时候,需要继承CL_BSP_CONTROLLER2,这样它的method中就是有很多继承过来的,我们需要重写一些函数(工具栏中的Redefine按钮),例如DO_INIT, DO_REQUEST,DO_HANDLE_EVENT,DO_FINISH_INPUT……

系统。

在DO_INIT中,我们一般创建数据处理类的实例

在DO_REQUEST 中,我们来处理创建view 及call view,及写入DISPATCH_INPUT这个函数来处理后续的用户事件等

在DO_HANDLE_EVENT中,我们来处理系统事件,例如单击某个控件等

  1. 1.     例如在DO_INIT中

method DO_INIT.

data: lo_gr_rpt type ref to ZCL_SUS_M_GR_RPT.

* Create model

lo_gr_rpt ?= create_model( class_name = 'ZCL_SUS_M_GR_RPT' model_id = 'GR_RPT' ).

DATA:  l_rfcdest TYPE rfcdest.

select single VALUE from zparam into l_rfcdest

where PARAM1 = 'GR_REPORT_DEST'.

if sy-subrc = 0.

call function 'ZRFC_SRM_GET_BURKS' destination l_rfcdest

EXPORTING

SPRAS = sy-LANGU

TABLES

BUKRS = lo_gr_rpt->d_bukrs.

call function 'ZRFC_SRM_GET_PURORG' destination l_rfcdest

TABLES

EKORG = lo_gr_rpt->D_EKORG.

call function 'ZRFC_SRM_GET_PLANT' destination l_rfcdest

TABLES

PLANT = lo_gr_rpt->D_WERKS.

endif.

endmethod.

  1. 2.     在DO_REQUEST中

method DO_REQUEST.

data: lo_view type ref to if_bsp_page.

data: lo_gr_rpt type ref to ZCL_SUS_M_GR_RPT.

* Create model

lo_gr_rpt ?= get_model('GR_RPT').

lo_view = create_view( view_name = '../invoice/gr_sel.inc' ).

lo_view->set_attribute( name = 'GR_RPT'  value = lo_gr_rpt ).

lo_view->set_attribute( name = 'URL'   value = url ).

call_view( lo_view ).

endmethod.

  1. 3.     在DO_HANDLE_EVENT中

method DO_HANDLE_EVENT.

data: lo_button_event           TYPE REF TO cl_htmlb_event_button.

data: lo_view type ref to if_bsp_page.

data: lo_gr_rpt type ref to ZCL_SUS_M_GR_RPT.

data: lv_bbp_guid type bbp_guid,

lt_guid            type bbp_t_sus_guids.

* RFC return value

data: l_rfc_err type string.

field-symbols: <fs_burks> type line of ZTB_BURKS,

<fs_ekorg> type line of ZTB_ekorg,

<fs_werks> type line of ZTB_BURKS.

* Create model

lo_gr_rpt ?= get_model('GR_RPT').

if htmlb_event is not initial.

IF htmlb_event->name = if_sus_controller_constants~gc_event_type_btn.

lo_button_event ?= htmlb_event.

*   ----  Button Event --------------------

if not lo_button_event is initial.

*    Click on Query button

if lo_button_event->server_event = 'GR.Query'.

global_messages->reset( ).

*          lo_gr_rpt->reset( ).

*        Check the mandatory fields on selection area

read table lo_gr_rpt->i_burks index 1 assigning <fs_burks>.

if <fs_burks> is initial or sy-subrc <> 0.

global_messages->add_message( condition = 'GR_RPT'

message =   'Please input company code'

severity = cl_bsp_messages=>co_severity_error ).

endif.

read table lo_gr_rpt->i_ekorg index 1 assigning <fs_ekorg>.

if <fs_ekorg> is initial or sy-subrc <> 0.

global_messages->add_message( condition = 'GR_RPT'

message =   'Please input Purchase Organization'

severity = cl_bsp_messages=>co_severity_error ).

endif.

read table lo_gr_rpt->i_werks index 1 assigning <fs_werks>.

if <fs_werks> is initial or sy-subrc <> 0.

global_messages->add_message( condition = 'GR_RPT'

message =   'Please input Plant'

severity = cl_bsp_messages=>co_severity_error ).

endif.

check global_messages->num_messages( ) = 0.

*        ------ Only the necessary field input and no error message continue

*{   INSERT         RGSK900009                                        1

*

*}   INSERT

*{   REPLACE        RGSK900009                                        2

*\          l_rfc_err = lo_ers_rpt->GET_ERS_DATA( ).

l_rfc_err = lo_gr_rpt->GET_GR_DATA( ).

*}   REPLACE

if l_rfc_err = 'X'.

global_messages->add_message( condition = 'RFC'

message = 'Call RFC failed!'

severity = messages->CO_SEVERITY_ERROR ).

global_event = space.

elseif l_rfc_err = 'S'.

global_messages->add_message( condition = 'RFC'

message = 'RFC destination not maintain in table ZPARAM'

severity = messages->CO_SEVERITY_ERROR ).

global_event = space.

elseif lo_gr_rpt->found is initial..

global_messages->add_message( condition = 'No data'

message = 'No data match your selection'

severity = messages->CO_SEVERITY_ERROR ).

global_event = space.

endif.

*    Click on Reset button

elseif lo_button_event->server_event = 'GR.Reset'.

lo_gr_rpt->reset( ).

endif.

endif.

endif.

endif.

data: event_id type string.

event_id = event.

if htmlb_event is not initial.

event_id = htmlb_event->id.

endif.

* Download to Excel... after table view showed

if event_id cs 'DOWNLOAD'.

data itab type ref to data.

get reference of lo_gr_rpt->E_OUTPUT_DATA into itab.

clear me->url.

me->url = zcl_es_bsp_elmnt_dwn_tbl_excl=>handle_event(

htmlb_event_ex = htmlb_event_ex

runtime        = runtime

itab           = itab ).

global_event = space.

endif.

endmethod.

  1. 4.     调用的view

<%@page language="abap"%>

<%@extension name="htmlb" prefix="htmlb"%>

<%@extension name="SRMSUS" prefix="sus" %>

<%@extension name="xhtmlb" prefix="xhtmlb" %>

<%@extension name="ZCHK" prefix="ZCHK" %>

<%

INCLUDE bbp_sus_ui_const.

%>

<!-- messages controller -->

<%@include file="framework/carrier_view_message.inc" %>

<htmlb:tray id = "GR_RPT"

title = "GR Report"

width = "60pt">

<htmlb:gridLayout id = "GR_RPT_Query"

rowSize = "15"

columnSize = "4"

cellSpacing = "10"

width = "100%">

<!--     Row 1              -->

<htmlb:gridLayoutCell rowIndex = "1"

columnIndex = "1"

width = "15%" >

<htmlb:label text = "<%= otr(BBP_SUS_UI/COMPANY_CODE)%>"

required = "true"

for = "GR.BURKS.InputField1" />

</htmlb:gridLayoutCell>

<htmlb:gridLayoutCell rowIndex = "1"

columnIndex = "2"

width = "15%" >

<htmlb:dropdownListBox id = "GR.BURKS.DROPDOWN1"

table = "//GR_RPT/D_BUKRS"

nameOfKeyColumn="BUKRS"

nameOfValueColumn="SEL_TXT"

selection="//GR_RPT/I_BURKS[1].low"

></htmlb:dropdownListBox>

</htmlb:gridLayoutCell>

<!--     Row 2              -->

<htmlb:gridLayoutCell rowIndex = "2"

columnIndex = "1"

width = "15%" >

<htmlb:label text = "<%= otr(BBP_SUS_UI/ZPURORG) %>"

required = "true"

for = "GR.EKORG.InputField1" />

</htmlb:gridLayoutCell>

<htmlb:gridLayoutCell rowIndex = "2"

columnIndex = "2"

width = "15%" >

<htmlb:dropdownListBox id = "GR.EKORG.DROPDOWN2"

table = "//GR_RPT/D_EKORG"

nameOfKeyColumn="EKORG"

nameOfValueColumn="SEL_TXT"

selection="//GR_RPT/I_EKORG[1].low"

></htmlb:dropdownListBox>

</htmlb:gridLayoutCell>

<htmlb:gridLayoutCell rowIndex = "2"

columnIndex = "3"

width = "8%" >

<htmlb:label text = "<%= otr(BBP_SUS_UI/TO)%>"

for = "GR.EKORG.InputField2" />

</htmlb:gridLayoutCell>

<htmlb:gridLayoutCell rowIndex = "2"

columnIndex = "4"

width = "8%" >

<htmlb:dropdownListBox id = "GR.EKORG.DROPDOWN3"

table = "//GR_RPT/D_EKORG"

nameOfKeyColumn="EKORG"

nameOfValueColumn="SEL_TXT"

selection="//GR_RPT/I_EKORG[1].HIGH"

></htmlb:dropdownListBox>

</htmlb:gridLayoutCell>

<!--     Row 3              -->

<htmlb:gridLayoutCell rowIndex = "3"

columnIndex = "1"

width = "15%" >

<htmlb:label text = "<%= otr(BBP_SUS_UI/PLANT)%>"

required = "true"

for = "GR.EKGRP.InputField1" />

</htmlb:gridLayoutCell>

<htmlb:gridLayoutCell rowIndex = "3"

columnIndex = "2"

width = "15%" >

<htmlb:dropdownListBox id = "GR.WERKS.DROPDOWN1"

table = "//GR_RPT/D_WERKS"

nameOfKeyColumn="WERKS"

nameOfValueColumn="WERKS"

selection="//GR_RPT/I_WERKS[1].low"

></htmlb:dropdownListBox>

</htmlb:gridLayoutCell>

<htmlb:gridLayoutCell rowIndex = "3"

columnIndex = "3"

width = "8%" >

<htmlb:label text = "<%= otr(BBP_SUS_UI/TO)%>"

for = "GR.WERKS.InputField2" />

</htmlb:gridLayoutCell>

<htmlb:gridLayoutCell rowIndex = "3"

columnIndex = "4"

width = "8%" >

<htmlb:dropdownListBox id = "GR.WERKS.DROPDOWN2"

table = "//GR_RPT/D_WERKS"

nameOfKeyColumn="WERKS"

nameOfValueColumn="WERKS"

selection="//GR_RPT/I_WERKS[1].HIGH"

></htmlb:dropdownListBox>

</htmlb:gridLayoutCell>

<!--     Row 4              -->

<htmlb:gridLayoutCell rowIndex = "4"

columnIndex = "1"

width = "15%" >

<htmlb:label text = "<%= otr(BBP_SUS_UI/GR_DATE)%>"

required = "true"

for = "GR.WERKS.InputField1" />

</htmlb:gridLayoutCell>

<htmlb:gridLayoutCell rowIndex = "4"

columnIndex = "2"

width = "15%" >

<htmlb:inputField id       = "GR.GR_DATE.InputField1"

value    = "//GR_RPT/I_GR_DATE[1].low"

disabled = "false" />

</htmlb:gridLayoutCell>

<htmlb:gridLayoutCell rowIndex = "4"

columnIndex = "3"

width = "8%" >

<htmlb:label text = "<%= otr(BBP_SUS_UI/TO)%>"

for = "GR.GR_DATE.InputField2" />

</htmlb:gridLayoutCell>

<htmlb:gridLayoutCell rowIndex = "4"

columnIndex = "4"

width = "8%" >

<htmlb:inputField id       = "GR.GR_DATE.InputField2"

value    = "//GR_RPT/I_GR_DATE[1].high"

disabled = "false" />

</htmlb:gridLayoutCell>

<P>

<HR>

<htmlb:gridLayoutCell rowIndex = "5"

columnIndex = "1"

colSpan = "2"

width = "35%" >

<htmlb:button id      = "Query"

onClick = "GR.Query"

text    = "<%= otr(BBP_SUS_UI/QUERY)%>" />

&nbsp; &nbsp;

<htmlb:button id      = "Reset"

onClick = "GR.Reset"

text    = "<%= otr(BBP_SUS_UI/RESET_VALUE) %>" />

</htmlb:gridLayoutCell>

<htmlb:gridLayoutCell rowIndex = "5"

columnIndex = "2"

width = "25%" >

</htmlb:gridLayoutCell>

</htmlb:gridLayout>

</htmlb:tray>

<% if gr_rpt->found = 'X'. %>

<htmlb:tray id = "GR_RPT_DET"

title = "<%= otr(BBP_SUS_UI/GR_LIST)%>"

width = "100%">

<htmlb:gridLayout id = "Download"

rowSize = "1"

columnSize = "1"

cellSpacing = "0"

width = "100%">

<htmlb:gridLayoutCell rowIndex = "1"

columnIndex = "1"

width = "100%"

horizontalAlignment = "left">

<ZCHK:downloadTableExcel id = "Download.GR"

disabled    = "true"

onDownload = "Download.GR"

display_url = "<%= url %>" />

</htmlb:gridLayoutCell>

</htmlb:gridLayout>

<htmlb:gridLayout id = "GR_RPT_Query"

rowSize = "2"

columnSize = "1"

cellSpacing = "0"

width = "100%">

<htmlb:gridLayoutCell rowIndex = "1"

columnIndex = "1"

width = "100%" >

<htmlb:tableView id            = "GR_RPT"

footerVisible = "true"

width         = "100%"

table         = "//GR_RPT/E_OUTPUT_DATA"

headerVisible = "true"

showNoMatchText  = "true"

selectionMode = "MULTISELECT"

headerText    = "List"

design           = "alternating"

visibleRowCount = "20"

>

<htmlb:tableViewColumn columnName          = "EBELN"

type                = "text"

title               = "<%= otr(BBP_SUS_UI/ZGR_RPT_EBELN) %>"

horizontalAlignment = "center" />

<htmlb:tableViewColumn columnName          = "MBLNR"

type                = "text"

title               = "<%= otr(BBP_SUS_UI/ZGR_RPT_MBLNR) %>"

horizontalAlignment = "center" />

<htmlb:tableViewColumn columnName          = "MJAHR"

type                = "text"

title               = "<%= otr(BBP_SUS_UI/ZGR_RPT_MJAHR) %>"

horizontalAlignment = "center" />

<htmlb:tableViewColumn columnName          = "ZEILE"

type                = "text"

title               = "<%= otr(BBP_SUS_UI/ZGR_RPT_ZEILE) %>"

horizontalAlignment = "center" />

<htmlb:tableViewColumn columnName          = "MATNR"

type                = "text"

title               = "<%= otr(BBP_SUS_UI/ZGR_RPT_MATNR) %>"

horizontalAlignment = "center" />

<htmlb:tableViewColumn columnName          = "MAKTX"

type                = "text"

title               = "<%= otr(BBP_SUS_UI/ZGR_RPT_MAKTX) %>"

horizontalAlignment = "left" />

<htmlb:tableViewColumn columnName          = "MENGE"

type                = "text"

title               = "<%= otr(BBP_SUS_UI/ZGR_RPT_MENGE) %>"

horizontalAlignment = "center" />

<htmlb:tableViewColumn columnName          = "MEINS"

type                = "text"

title               = "<%= otr(BBP_SUS_UI/ZGR_RPT_MEINS) %>"

horizontalAlignment = "center" />

<htmlb:tableViewColumn columnName          = "BUDAT"

type                = "text"

title               = "<%= otr(BBP_SUS_UI/ZGR_RPT_BUDAT) %>"

horizontalAlignment = "center" />

<htmlb:tableViewColumn columnName          = "XBLNR"

type                = "text"

title               = "<%= otr(BBP_SUS_UI/ZGR_RPT_XBNLR) %>"

horizontalAlignment = "left" />

</htmlb:tableView>

</htmlb:gridLayoutCell>

</htmlb:gridLayout>

</htmlb:tray>

<% endif. %>

其page attribute

gr_rpt  TYPE REF TO    ZCL_SUS_M_GR_RPT

url  TYPE    STRING

结果如下:

 

希望以上代码对大家能有所帮助,尤其是一些语法上的。如有问题,请留言。

下面的代码介绍如何在表格里嵌入图标,及与用户交互。

效果如下:

转:http://blog.chinaunix.net/uid-465882-id-2115965.html

SAP web 开发 (第二篇 bsp 开发 mvc模式 Part1 )的更多相关文章

  1. SAP web 开发 (第二篇 bsp 开发 mvc模式 Part2 )

    单击第一个图标,第一个图标突出显示,单击第二个图标,第一个变灰,第二个突出显示,反之一样.单击history读取历史记录. Controller ZCL_SUS_C_ORDER_CHANGE 1.   ...

  2. 第二篇 界面开发 (Android学习笔记)

    第二篇 界面开发 第5章 探索界面UI元素 ●The Android View Class     ●△Widget设计步骤 需要修改三个XML,以及一个class: 1)第一个xml是布局XML文件 ...

  3. iOS开发——高级技术精选&底层开发之越狱开发第二篇

    底层开发之越狱开发第二篇 今天项目中要用到检查iPhone是否越狱的方法. Umeng统计的Mobclick.h里面已经包含了越狱检测的代码,可以直接使用 /*方法名: * isJailbroken ...

  4. iOS开发UI篇—iOS开发中三种简单的动画设置

    iOS开发UI篇—iOS开发中三种简单的动画设置 [在ios开发中,动画是廉价的] 一.首尾式动画 代码示例: // beginAnimations表示此后的代码要“参与到”动画中 [UIView b ...

  5. iOS开发UI篇—IOS开发中Xcode的一些使用技巧

    iOS开发UI篇—IOS开发中Xcode的一些使用技巧 一.快捷键的使用 经常用到的快捷键如下: 新建 shift + cmd + n     新建项目 cmd + n             新建文 ...

  6. iOS开发UI篇—iPad开发中得modal介绍

    iOS开发UI篇—iPad开发中得modal介绍 一.简单介绍 说明1: 在iPhone开发中,Modal是一种常见的切换控制器的方式 默认是从屏幕底部往上弹出,直到完全盖住后面的内容为止 说明2: ...

  7. android 串口开发第二篇:利用jni实现android和串口通信

    一:串口通信简介 由于串口开发涉及到jni,所以开发环境需要支持ndk开发,如果未配置ndk配置的朋友,或者对jni不熟悉的朋友,请查看上一篇文章,android 串口开发第一篇:搭建ndk开发环境以 ...

  8. Web开发的分层结构与MVC模式

    1.分层结构 所谓分层结构.把不同的功能代码封装成类,把相同功能的类封装在一个个的包中,也叫层.功能归类如下: 实体类: 封装数据,是数据的载体,在层与层之间进行传递,数据也就传递了.比如说要传递学生 ...

  9. 微信支付之JSAPI开发-第二篇:业务流程详解与方案设计

    微信支付流程 流程: 上图的网址为:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_4 如上图所示,微信网页支付的具体流程大致分为 ...

随机推荐

  1. CI 框架访问 http://[::1]/yourproject/

    Chances are you have left the base url blank/* |---------------------------------------------------- ...

  2. ADT中通过Android SDK Manager去安装x86的image时无法下载

    参考:http://www.crifan.com/adt_android_sdk_manager_can_not_download_package_x86_image/

  3. sudo service docker start

    sudo service docker start sudo docker run -t -i ubuntu:14.04 /bin/bash docker ps -l CONTAINER ID IMA ...

  4. 打包app命令行

    $ cd myApp $ ionic platform add android $ ionic build android $ ionic emulate android

  5. 模板引擎:ArtTemplate 使用入门和简单的使用

    下载地址:https://github.com/aui/artTemplate 快速上手请参考:https://github.com/aui/artTemplate 通过阅读artTemplate原文 ...

  6. CSS背景样式

    CSS是级联样式表,用来表现HTML等文件样式的语言,CSS能够真正做到网页的表现与内容分离的设计语言,也就是说,做好了一款网页,可以通过另一个后缀名是css的文件进行修改其中的样式,不过在html的 ...

  7. HTTP笔记之一

    1  URL 统一资源定位符(URL)是资源标识符最常见的格式.大部分的URL都遵循一种标准格式,这种格式包含三个部分. URL的第一部分:方案(scheme),说明了访问资源所使用的协议类型.通常是 ...

  8. iOS - OC NSStream 文件流

    前言 @interface NSStream : NSObject @interface NSOutputStream : NSStream 1.文件流的使用 NSString *filePath = ...

  9. iOS AFNetworking中cookie的读取与设置

    参考: http://blog.csdn.net/zhaoxy_thu/article/details/20532879 实际上AFNetworking中并没有专门针对cookie封装的代码,但是由于 ...

  10. nginx 缓存机制

    nginx 缓存机制   Nginx缓存的基本思路 利用请求的局部性原理,将请求过的内容在本地建立一个副本,下次访问时不再连接到后端服务器,直接响应本地内容 Nginx服务器启动后,会对本地磁盘上的缓 ...