我有一個場景,我希望N個視圖實例在視圖上的TransparentContainer
,每個接收不同的參數。爲了實現這一點,我寫了一些邏輯來動態創建cl_wd_view_container_uielement
,將它添加到cl_wd_uielement_container
(主視圖上的TransparentContainer
),然後使用動態導航發送插件以發送我的參數。代碼可以在下面找到。將視圖的實例動態添加到TransparentContainer中
這一切都適用於一個問題:創建的實例不是唯一的,所以我基本上添加了N個相同視圖的副本。 N個插件被觸發並處理,但最後一個設置所有視圖的參數,因爲只有一個實例。該視圖的WDDOMODIFYVIEW
也只能觸發一次。
下面的代碼被重新利用,並從工作版本清除,所以我知道這是可能的。最大的區別是我在我的場景中添加了來自同一個WDC的視圖。在原始應用程序中,動態添加的視圖具有自己的Web Dynpro組件,調用者還提供動態創建的組件用法。
是否有某種方法可以創建多個我缺少的實例?在這種情況下,我應該提供一個組件使用情況嗎?我一直在修補這個問題幾個小時,但沒有取得任何進展,所以我歡迎任何意見讓我走上正軌。從主視圖
代碼:
DATA:
lo_container TYPE REF TO cl_wd_uielement_container,
lo_subview TYPE REF TO cl_wd_view_container_uielement,
lo_flow_data TYPE REF TO cl_wd_flow_data,
lo_view_controller TYPE REF TO if_wd_view_controller,
lo_component_usage TYPE REF TO if_wd_component_usage,
lo_wdr_view TYPE REF TO cl_wdr_view,
lo_component_api TYPE REF TO if_wd_component,
lt_posts TYPE ztt_fi_vernot_posts,
ls_post LIKE LINE OF lt_posts,
lt_parameters TYPE wdr_event_parameter_list,
ls_parameter TYPE wdr_event_parameter,
lv_view_id TYPE string,
lv_source_plug_name TYPE string,
lv_target_embed_pos TYPE string,
lv_param_value TYPE REF TO DATA.
FIELD-SYMBOLS:
<lv_param_value> TYPE bu_partner
.
lt_posts = wd_this->mo_model->get_posts(iv_open = abap_true).
" Retrieve and refresh the view container.
lo_wdr_view ?= wd_this->wd_get_api().
lo_container ?= lo_wdr_view->root_element.
lo_container ?= lo_wdr_view->get_element('TC_POSTS').
lo_container->remove_all_children().
LOOP AT lt_posts INTO ls_post.
" View and plug IDs should be unique.
CONCATENATE 'POSTS_' ls_post-index INTO lv_view_id.
CONCATENATE 'OUTPLUG_' ls_post-index INTO lv_source_plug_name.
" Create a new view.
lo_subview = cl_wd_view_container_uielement=>new_view_container_uielement(id = lv_view_id).
lo_flow_data = cl_wd_flow_data=>new_flow_data(element = lo_subview).
lo_subview->set_layout_data(lo_flow_data).
lo_subview->set_layout_data(cl_wd_flow_data=>new_flow_data(element = lo_subview)).
lo_container->add_child(lo_subview).
lo_view_controller = wd_this->wd_get_api().
CONCATENATE 'V_MAIN/' lv_view_id INTO lv_target_embed_pos.
* This was present in the source, returning a component usage via create_comp_usage_of_same_type()
* lo_component_usage = wd_comp_controller->get_component(iv_compcnt = ls_post-index ).
lo_view_controller->prepare_dynamic_navigation(
source_window_name = 'W_MAIN'
" Found in the window structure for this View
source_vusage_name = 'V_MAIN_USAGE_0'
source_plug_name = lv_source_plug_name
" target_component_name = '[WDC name]' " Optional?
" target_component_usage = lo_component_usage->name " Optional?
target_view_name = 'V_POSTS'
target_plug_name = 'SET_PARAMS'
target_embedding_position = lv_target_embed_pos).
" Fill the paramaters. Note that the values should be passed as pointers.
REFRESH lt_parameters.
CLEAR ls_parameter.
ls_parameter-name = zcl_fi_vernot=>gcs_plugs-params-bp.
CREATE DATA lv_param_value LIKE ls_post-bp.
ASSIGN lv_param_value->* TO <lv_param_value>.
<lv_param_value> = ls_post-bp.
ls_parameter-value = lv_param_value.
INSERT ls_parameter INTO TABLE lt_parameters.
" Do the same for the contract.
CLEAR ls_parameter.
ls_parameter-name = zcl_fi_vernot=>gcs_plugs-params-contract.
CREATE DATA lv_param_value LIKE ls_post-contract.
ASSIGN lv_param_value->* TO <lv_param_value>.
<lv_param_value> = ls_post-contract.
ls_parameter-value = lv_param_value.
INSERT ls_parameter INTO TABLE lt_parameters.
" Finally, fire the plug.
wd_this->wd_get_api()->fire_plug(plug_name = lv_source_plug_name parameters = lt_parameters).
ENDLOOP.