我有一个场景,我想在一个视图的TransparentContainer
上有N个视图实例,每个实例接收不同的参数。为了实现这一点,我编写了一些逻辑来动态创建cl_wd_view_container_uielement
,将其添加到cl_wd_uielement_container
(主视图上的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.
这个问题不仅限于视图的动态生成,而且当您想在同一组件的窗口中多次使用特定视图时也会发生。只有一个实例被创建,所以重用是非常有限的。
唯一的解决方案是将View分离到它自己的Web Dynpro组件中,或者创建活动WDC的多个组件用法,并在动态导航中使用它们。