将视图的实例动态添加到TransparentContainer

时间:2014-05-23 14:08:57

标签: sap abap webdynpro

我有一个场景,我希望视图中的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.

1 个答案:

答案 0 :(得分:2)

此问题不仅限于动态生成视图,而且还要在同一组件的窗口中多次使用特定视图时发生。只创建了一个实例,因此重用非常有限。

唯一的解决方案是将View off分离到自己的Web Dynpro组件,或创建活动WDC的多个组件用法并在动态导航中使用它们。