cancel
Showing results for 
Search instead for 
Did you mean: 

dynamic ui elemnts

Former Member
0 Kudos

hi experts,

how to create view container ui element dynamically and how to embed another componet view to the view container dynamically

how to assign colors to the tray

Thanks&regards,

sriman gorantla

Accepted Solutions (1)

Accepted Solutions (1)

ramakrishnappa
Active Contributor
0 Kudos

Hi Sriman,

You can create the view container ui element dynamically as below


data:

  lo_vcu              TYPE REF TO cl_wd_view_container_uielement,

  lo_container       TYPE REF TO cl_wd_uielement_container.

       lo_vcu =

cl_wd_view_container_uielement=>new_view_container_uielement(

                  id                     = 'VCU_TEST_123'.

  lo_container ?= view->get_root_element( ).

  lo_container->add_child( lo_vcu ).

Now, you need to get the view usage and target position of view container from window.

  • get the view usage from view controller by using method get_view_usage( )
  • Get the embedding position by using method lv_curr_embed_position = lo_view_usage->get_embedding_position
  • Prepare the target embedding position by concatenating '.VIEW_NAME/VCU_TEST_123' into lv_target_embed_position
  • Now, using method DO_DYNAMIC_NAVIGATION( ) , embed the used component and its interface view inside the view cocntainer

Hope this helps you.

Regards,

Rama

Former Member
0 Kudos

hi ram,

it's asking

source window name

source vusage mane

source plug name

mandatory parameters in do_dynamic_navigation( ).

Thanks&Regards,

sriman.

ramakrishnappa
Active Contributor
0 Kudos

Hi Sriman,

You have to create an outbound plug for your SOURCE window.

Please find the sample code:


  DATA:

      lv_source_vusage_name   TYPE string,

      lv_source_window_name   TYPE string,

      lv_source_plug_name     TYPE string,

      lv_target_plug_name     TYPE string,

      lv_curr_embed_pos       TYPE string,

      lv_target_embed_pos     TYPE string,

      lv_target_embed_pos_prev TYPE string,

      lv_target_comp_name     TYPE string,

      lv_target_view_name     TYPE string,

      lo_view_ctrl            TYPE REF TO if_wd_view_controller,

      lo_view_usage           TYPE REF TO if_wd_rr_view_usage.

  lo_view_ctrl = wd_this->wd_get_api( ).

"get view usage ref

  lo_view_usage = lo_view_ctrl->get_view_usage( ).

  "Check if view usage is bound

  IF lo_view_usage IS BOUND.

    "get view usage name

    lv_source_vusage_name =  lo_view_usage->get_name( ).

    "prepare embedding position

    lv_curr_embed_pos =

    lo_view_usage->get_embedding_position( ).

    lv_target_embed_pos = 'V_DYNAMIC_NAVIGATE/VCU_DYNAMIC'.

  ELSE.

    RETURN.

  ENDIF.

  lv_source_plug_name = 'TO_DYNAMIC'.

  lv_target_comp_name = 'ZWD_RK_TEST2'.

  lv_target_view_name = 'W_MAIN'.

  lv_target_plug_name = 'IN_DATA'.

  lv_source_window_name = 'W_DYNAMIC'.

  lo_view_ctrl->do_dynamic_navigation(

            EXPORTING

              source_window_name        = lv_source_window_name

              source_vusage_name        = lv_source_vusage_name

              source_plug_name          = lv_source_plug_name

              target_component_name     = lv_target_comp_name

*          target_component_usage    = id_tab

              target_view_name          = lv_target_view_name

              target_plug_name          = lv_target_plug_name

              target_embedding_position = lv_target_embed_pos ).

Note:Change the view/window/plug names as per your requirement

Hope this helps you.

Regards,

Rama

Answers (3)

Answers (3)

Former Member
0 Kudos

This is a little bit tricky, but can be made. One question: Does your requirement allow a component interface that can be defined at design time and all the possible components to be embedded implement?

I'm not quite sure if it is possible without an interface at all.

Here's a little code snippit that can be used as guide line. (There may be some adjustments needed)

---

Definition of the Component Interface:

This Interface must have a method:

WD_GET_API with returning parameter:

result TYPE REF TO if_wd_controller

.

---snipit to create and navigate to the dynamically instantiated component

DATA:

lr_cmp_api TYPE REF TO if_wd_component,

lr_component_usage TYPE REF TO if_wd_component_usage,

lr_if_controller TYPE REF TO object ,

lr_if_comp_controller TYPE REF TO IWCI_NAME_OF_YOUR_INTERFACE, " You need this interface see above

lr_if_view_controller TYPE REF TO if_wd_controller,

lr_view_controller_api TYPE REF TO if_wd_view_controller.

DATA:

lv_component_name TYPE string, "Name of your dynamic component

lv_view_name TYPE string. "Name of the dynamic view

*Create Component Group

      lr_cmp_api = wd_comp_controller->wd_get_api( ).

      IF lr_cmp_api->has_cmp_usage_group( 'COMPGROUP' ) IS INITIAL.

        wd_comp_controller->cmp_usage_group = lr_cmp_api->create_cmp_usage_group(

                                                        name   =  'COMPGROUP'

                                                        used_component = lv_component_name ).

      ENDIF.

* Create Dynamic component usage

        wd_comp_controller->cmp_usage_group->add_component_usage(

                                       name = 'COMPONENTUSAGE'

                                       embedding_position = lv_view_name

                                       used_component     = lv_component_name ).

      ENDIF.

*Dynamic navigation

      lr_component_usage = wd_comp_controller->cmp_usage_group->get_component_usage( name = 'COMPONENTUSAGE' ).

      IF lr_component_usage->has_active_component( ) IS INITIAL.

        lr_component_usage->create_component( lv_component_name ).

      ENDIF.

* Start of Addition

      lr_if_controller = lr_component_usage->get_interface_controller( ).

      lr_if_comp_controller ?= lr_if_controller.

      lr_if_view_controller = wd_this->wd_get_api( ).

      lr_view_controller_api = wd_this->wd_get_api( ).

   "This is a call of the dynamic navigation using a outbound plug defined static before! You may try the same method but as part of the IF IF_WD_NAVIGATION_SERVICES_NEW

   "IF_WD_NAVIGATION_SERVICES_NEW~PREPARE_DYNAMIC_NAVIGATION

      lr_view_controller_api->prepare_dynamic_navigation(

      source_window_name        = 'WINDOW_NAME' " Name of the current Window

      source_vusage_name        = 'CURRENT_VIEW_USAGE_NAME' "Name of the current View Usage as set in the window

      source_plug_name          = 'CURRENT_OUT_PLUG_NAME' "Name of the Outplug to be used for navigation

      target_component_name     = lv_component_name

      target_component_usage    = 'COMPONENTUSAGE'

      target_view_name          = 'TARGET_WINDOW_OUT_PLUG_NAME' "Name of the Outbound Plug in the target Window that is linked to the view that is to be shown.

      target_plug_name          = 'DEFAULT' "Name of the target's inbound plug to be used

      target_embedding_position = 'UI_EMBED_VIEW_NAME' "Name of the ViewContainerUIElement of the current view to be used to embed the target window

   ).

      wd_this->fire_CURRENT_OUT_PLUG_NAME_plg( ). "Insert the plug name like used in "SOURCE_PLUG_NAME"

NagaPrakashT
Contributor
0 Kudos

Hi Sriman,

A View Container UI Element can hold n number of Views, but at run time it can show only 1 View.

So based on some condition you can switch the views may be that that can achieve dynamic behavior of views.

Best Regards,

Naga

former_member197475
Active Contributor
0 Kudos

Hi Sri,

Why are you going for dynamic action?

It's quite easy and can be well modeled thorugh An example for creating Viewcontainer UI element - Web Dynpro ABAP - SCN Wiki.

BR,

RAM.

Former Member
0 Kudos

hi ram,

tnx for ur reply.

i know how to create view container statically i want to create dynamically as per reqirement.

BR,

sriman