ABAP Webdynpro里Component Usage的用法
In NET311 the topic component usage clone is discussed there. One example is also given there: The user of a Web Dynpro application can mark multiple lines of a table to display details for each selected data set. The details of one data set is displayed by one usage of a certain component. Thus, the number of component usages equals the number of marked lines, which is not known at design time.
The prerequisite for cloning any component usage is, that a single usage of this component has been defined at design time. Any controller having added the name of the static component usage to the list of used controllers / components can then create additional usages of the same component. Each component usage must have a unique name.
I will reuse the component created in the blog Step by Step to create UI elements and context node attribute in the runtime . After I maintain the content number and click create button, the label and text view together with their bound context node attribute will be generated in the runtime. The value of text view “Echo from Usage clone:” is returned by the cloned component usage.
(1) Create a simple component ZDYNAMICUSAGE which will be consumed as component usage later. Implement the echo method in component controller.
(2) In order to use component usage, there must be at least one static component usage.Also define usage of the interface controller in the consumer view controller.
(3) In method CREATE_CONTEXT, just enhance one line. ( In the original example, I just set the value of newly-generated context attribute to its attribute name)
method CREATE_CONTEXT .
CONSTANTS: cv_value type string value 'VALUE'.
data(lo_node) = wd_context->get_child_node( 'DYNAMIC' ).
data(lo_node_info) = lo_node->get_node_info( ).
data(lt_attributes) = lo_node_info->get_attributes( ).
DO iv_count TIMES.
DATA(lv_attribute_name) = cv_value && sy-index.
READ TABLE lt_attributes WITH KEY name = lv_attribute_name TRANSPORTING NO FIELDS.
IF sy-subrc <> 0.
data(ls_attribute_prop) = VALUE wdr_context_attribute_info( NAME = lv_attribute_name
TYPE_NAME = 'STRING' ).
lo_node_info->add_attribute( attribute_info = ls_attribute_prop ).
DATA(lv_value) = wd_this->get_value_by_index( sy-index ).
lo_node->set_attribute( name = lv_attribute_name value = lv_value ).
ENDIF.
ENDDO.
endmethod.
(4) Define one attribute in view controller, which is an internal table to store all references of component usage instance.
In view controller WDDOINT, insert the static component usage to the internal table. The internal table would have the first line as static component usage instance and all remaining ones for cloned component usage from the static one.
method WDDOINIT .
DATA(lo_static_usage) = wd_this->wd_cpuse_zclone_example( ).
APPEND lo_static_usage TO wd_this->gt_cmp_usages.
endmethod.
(5) Implement the method get_value_by_index which is called in step3. I will read the internal table gt_cmp_usages by index. Index 1 means this is a static component usage so I directly use the one return from wd_this->wd_cpuse_zclone_example( ). Or else the left one will be cloned from the static one. Since the usage name should be unique, so I use a prefix and an index to fulfill the uniqueness.
method GET_VALUE_BY_INDEX .
DATA(lo_static_com_usage) = wd_this->wd_cpuse_zclone_example( ).
DATA: lo_generic_usage TYPE REF TO if_wd_component_usage,
lo_interface_control TYPE REF TO ZIWCI_DYNAMICUSAGE.
READ TABLE wd_this->gt_cmp_usages ASSIGNING FIELD-SYMBOL(<usage>) INDEX iv_index.
CASE iv_index.
WHEN 1.
IF lo_static_com_usage->has_active_component( ) IS INITIAL.
lo_static_com_usage->create_component( ).
ENDIF.
lo_generic_usage = lo_static_com_usage.
WHEN OTHERS.
READ TABLE wd_this->gt_cmp_usages ASSIGNING FIELD-SYMBOL(<dyn_usage>) INDEX iv_index.
IF sy-subrc <> 0.
DATA(lv_usage_name) = 'DYNAMIC_USAGE' && sy-index.
data(lo_dyn_usage) = lo_static_com_usage->create_comp_usage_of_same_type( name = lv_usage_name ).
APPEND lo_dyn_usage TO wd_this->gt_cmp_usages.
ENDIF.
IF lo_dyn_usage->has_active_component( ) IS INITIAL.
lo_dyn_usage->create_component( ).
ENDIF.
lo_generic_usage = lo_dyn_usage.
ENDCASE.
lo_interface_control ?= lo_generic_usage->get_interface_controller( ).
rv_output = lo_interface_control->get_field_value( iv_index ).
endmethod.
In the debugger I would observe that every component usage in gt_cmp_usages are unique:
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
- Mesos+Marathon+Docker构建docker集群化管理
- 【测试】两种数据库,四种分页算法的效率比较
- 【开源】QuickPager 分页控件的内部结构,和OO原则与设计模式
- 【实体类变形】—— 元数据(另类ORM) 描述字段的数据
- 【陆勤践行】奇异值分解 - 最清晰易懂的svd 科普
- 快速自检电脑是否被黑客入侵过(Linux版)
- 【陆勤践行】机器学习中距离和相似性度量方法
- 运维工作常用的shell命令
- SVN搭建指南
- python3 源码编译并配置jupyterhub
- 【小试身手】几个自定义控件的组合应用,实现简单的“增删改查”功能(有源码)
- 如何手动给Docker容器设置静态IP
- Golang正则模块使用
- 图像分割(四)
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 如何在SAP S/4HANA里创建自定义的partner function
- Rust 往事 | Loop 和 While True 之争
- 数字成像系统概述
- 在SAP C4C里使用Restful服务消费SAP S/4HANA的标准功能
- SAP Spartacus里的StorefrontConfig静态类型
- SAP Spartacus B2cStorefrontModule.withConfig的实现
- SAP Spartacus 页面元数据
- leetcode-easy-array-合并两个有序数组
- django配置mysql数据库
- Spring整合WebSocket
- Linux 命令(138)—— nc 命令
- # 全网最细 | 21张图带你领略集合的线程不安全
- grafana踩坑记录
- TensorFlow函数:tf.image.crop_to_bounding_box
- tf.newaxis