`
JerryWang_SAP
  • 浏览: 1062825 次
  • 性别: Icon_minigender_1
  • 来自: 成都
文章分类
社区版块
存档分类
最新评论

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的原创文章,请关注公众号"汪子熙":

0
1
分享到:
评论

相关推荐

    webdynpro for abap

    6-《Web Dynpro for ABAP - Component Usage.pdf》:组件是Web Dynpro的基本构建块,包含逻辑和视图元素。这部分内容会深入讲解如何复用和组合组件,以创建更复杂的业务流程。 学习Web Dynpro for ABAP,你需要理解...

    webdynpro 进阶篇.zip

    WebDynpro For ABAP 进阶 案例一: WebDynpro中事件执行顺序 - 261 - 案例二: 快速搜索WebDynpro信息 - 268 - 案例三: Upload Excel using WebDynpro - 271 - 案例四: SICF为某一WD App配置Logon page - 277 - ...

    WebDynpro for ABAP

    Web Dynpro for ABAP是SAP提供的一种用于开发企业级Web应用程序的技术,它专注于构建复杂的、数据密集型的用户界面。以下是对Web Dynpro for ABAP的一些关键知识点的详细解释: 1. **Context Binding**:上下文绑定...

    Programming dynamic ALV in WebDynpro for ABAP

    ### 编程动态 ALV 在 WebDynpro for ABAP 中的应用 #### 概述 本文旨在探讨如何在 WebDynpro for ABAP 中编程实现动态 ALV(Application List Viewer)。通过本教程,您将学会如何根据用户的选择动态地构建 ALV 的...

    Web Dynpro ALV控件使用.docx

    ### Web Dynpro ALV 控件使用详解 #### 一、概述 在 SAP 开发领域,Web Dynpro 是一种用于构建用户界面的技术。其中,ALV(Application List Viewer)控件常用于显示表格数据,提供了丰富的功能,如排序、筛选、...

    Web Dynpro Overview.ppt

    Web Dynpro for Java和Web Dynpro for ABAP是两种针对不同技术栈的实现,它们共享相同的元数据模型,但通过Web Dynpro Converter进行转换,以适应ABAP和Java的差异。 总的来说,SAP Web Dynpro 提供了一个强大的...

    Tutorial6 - Component Usage

    在给定的文件信息中,我们探讨的是关于Web Dynpro for ABAP的组件使用教程,具体为Tutorial6。Web Dynpro是一种用于构建企业级应用程序的用户界面开发框架,由SAP提供,主要用于ABAP(Advanced Business Application...

Global site tag (gtag.js) - Google Analytics