二维码

[教程] REUSING A VIEW IN ANOTHER COMPONENT

Twilight发表于 2015-12-04 01:44Twilight 最后回复于 2015-12-04 01:44 [复制链接] 4876 0

Read ‘What it takes to reuse a view’ before reading this chapter.
Go to the component ->run time repository and create a component usage.
Click on edit button and right click on component usage and choose the option add component usage.
usage 1.jpg

In the next Dialog box, give name to the component usage and details of interface view and component that we want to reuse.
usage 2.jpg
  
Choose continue once you enter the details. Now this interface view will act as view in our own component.
Add this view to the overview page.
usage 3.jpg

Save the runtime repository. Go to the configuration tab of overview page and add the new view to displayed assignment block section.
usage 4.jpg
  
Now we need to take care of data. In the previous chapter, we know that there is one context node BTPARTNERSET of component controller of component BTPARTNER. So we will create one new same context node at component controller level in our own component.

Go to the component controller and create one context node with base entity BTPartnerSet.
usage 5.jpg

Give the base entity name and complete the wizard.
usage 6.jpg

We have created the context node. Then we need to give the data to this context node. There are no of ways doing it.
Let us do it through coding.
As we know, in the event handler (will trigger whey user clicks on hyper link) of result view, we got the BTAdminh entity. We will fetch related BTPARTNER SET from it and feed it to the context node of component controller.

Do the following changes in the event handler. Save and activate it.
  1. METHOD eh_onobjectid.

  2.   DATA:lr_clickedrecord TYPE REF TO cl_crm_bol_entity,
  3.        lr_order TYPE REF TO cl_crm_bol_entity,
  4.        lr_header  TYPE REF TO cl_crm_bol_entity,
  5.        lr_col  TYPE REF TO cl_crm_bol_bo_col,
  6.        lr_custcontroller TYPE REF TO zl_ztutcomp_cucosearch_impl,
  7.        lv_index TYPE i.

  8.   DATA:lr_partnerset TYPE REF TO cl_crm_bol_entity,
  9.        lr_col1 TYPE REF TO cl_crm_bol_bo_col,
  10.        lr_component TYPE REF TO zl_ztutcomp_bspwdcomponen_impl.

  11.   "find out the record index on which user clicked.
  12.   cl_thtmlb_util=>get_event_info( EXPORTING iv_event = htmlb_event_ex
  13.                                   IMPORTING ev_index = lv_index ).
  14.   CHECK lv_index IS NOT INITIAL.

  15.   "based on the index,fetch the record from the result context node.
  16.   lr_clickedrecord ?= me->typed_context->result->collection_wrapper->find( iv_index = lv_index ).
  17.   CHECK lr_clickedrecord IS BOUND.

  18.   "lr_clickedrecord is of type BTQRSrvCon,we need to get BTAdminH from it.
  19.   lr_order ?= lr_clickedrecord->get_related_entity( iv_relation_name = 'BTADVSSrvCon' ).
  20.   CHECK lr_order IS BOUND.
  21.   lr_header ?= lr_order->get_related_entity( iv_relation_name = 'BTOrderHeader' ).
  22.   CHECK lr_header IS BOUND.
  23.   CREATE OBJECT lr_col.
  24.   lr_col->if_bol_bo_col~add( lr_header ).

  25.   "get the custom controller instance.
  26.   lr_custcontroller ?= me->get_custom_controller( 'ZTUTCOMPONENT/CuCoSearch' ).

  27.   "add the found recored to the header context node of custom controller.
  28.   lr_custcontroller->typed_context->header->collection_wrapper->set_collection( lr_col ).

  29.   "get the component controller.
  30.   lr_component ?= me->comp_controller.
  31.   lr_partnerset ?= lr_header->get_related_entity( iv_relation_name = 'BTHeaderPartnerSet' ).
  32.   IF lr_partnerset IS BOUND.
  33.     CREATE OBJECT lr_col1.
  34.     "add the partnerset entity to the collection.
  35.     lr_col1->if_bol_bo_col~add( lr_partnerset ).
  36.     "set the collection to the context node of component controller.
  37.     lr_component->typed_context->btpartnerset->collection_wrapper->set_collection( lr_col1 ).
  38.   ENDIF.

  39.   "calling the outbound plug of the view to start the navigation.
  40.   op_tooverviewpage( ).

  41. ENDMETHOD.
复制代码

(This is just part of changed code regarding above scenario. Previous code remains as it as ).  once we got the header entity BTAdminh, we got its related entity BTPARTNERSET using the relation. Once we got the required record we added it to the collection and this collection is fed to the context node of component controller.

Data feeding to context node is done. There is one more important binding left between the context node of our component controller to the context node of BTPARTNER component controller. As discussed we will use the method WD USAGE INITIALIZE  to do this job.

Go to the component controller and redefine above mentioned method.
ANOTHER COMPONENT 8.jpg

Once you redefine, and then double click on that method to open it. write the following code in it and activate it.
  1. METHOD wd_usage_initialize.

  2.   CALL METHOD super->wd_usage_initialize
  3.     EXPORTING
  4.       iv_usage = iv_usage.

  5.   CASE iv_usage->usage_name.
  6.     WHEN 'CuPartner'. "component usage name
  7.       CALL METHOD iv_usage->bind_context_node
  8.         EXPORTING
  9.           iv_controller_type  = cl_bsp_wd_controller=>co_type_component
  10.           iv_target_node_name = 'BTPARTNERSET'  "node in current component
  11.           iv_node_2_bind      = 'BTPARTNERSET'. "node in different component
  12.     WHEN OTHERS.
  13.   ENDCASE.

  14. ENDMETHOD.
复制代码

Sharing data across context nodes of different components is done.
Test the application. If service contract has any partners, then data will be displayed in the partner assignment block.
usage 8.jpg
回复

使用道具 举报

快速回帖

本版积分规则
您需要登录后才可以回帖 登录 | 注册有礼

快速回复 返回顶部 返回列表