cancel
Showing results for 
Search instead for 
Did you mean: 

Embed a view dynamically in a ViewContainerUIElement

Former Member
0 Kudos

Hi all,

is it possible to embed a view dynamically into a View Container UI Element?

I'm able to create this ViewContainerUIElement by code, but I also want to embed the view per code!

I don't want to put it fixed in the component usage in the component controller.

The suitable solution would be:

3 variables:

a flag "show_view"

"view_name"

"component_name"

if show_view is true -> load view_name from component_name in ViewContainerUIElement.

Is a szenario like this possible?

Thanks a lot, points will be awarded for sure!

Steffi

Accepted Solutions (1)

Accepted Solutions (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

I don't believe you can just supply the inner component and view name dynamically because you have to have an embedding in the window. Instead you should use dynamic navigation. You can use the do_dynamic_navigation method to perform dynamic navigation with a ViewContainerUIElement as the target. Here is an example:

method onactionnavigation .

  data node_index type integer.
  context_element->get_attribute(
      exporting name = 'INDEX'
      importing value = node_index ).

  data:
    l_api_main type ref to if_wd_view_controller.

  data: target_component_name type string,
        target_view_name      type string,
        source_plug_name      type string.
  case node_index.
    when 1.
      target_component_name = 'ZZ_00_SFLIGHT'.
      target_view_name      = target_component_name.
      source_plug_name      = 'OUT_PLUG1'.
    when 2.
      target_component_name = 'ZZ_00_BAPIFLIGHT'.
      target_view_name      = target_component_name.
      source_plug_name      = 'OUT_PLUG2'.
    when 3.
      target_component_name = 'ZZ_00_BAPINAV'.
      target_view_name      = target_component_name.
      source_plug_name      = 'OUT_PLUG3'.
    when 4.
      target_component_name = 'ZZ_00_BOOKINGS'.
      target_view_name      = 'ZZ_00_BAPINAV'.
      source_plug_name      = 'OUT_PLUG4'.
    when 5.
      target_component_name = 'Z_SELECT_OPTIONS'.
      target_view_name      = target_component_name.
      source_plug_name      = 'OUT_PLUG5'.
    when 6.
      target_view_name      = 'LOCAL_TEST'.
      source_plug_name      = 'OUT_PLUG6'.
    when 7.
      target_component_name = 'Z00_WDT_FLIGHTLIST_SIMPLE'.
      target_view_name      = 'MAIN'.
      source_plug_name      = 'OUT_PLUG7'.
    when 8.
      target_component_name = 'Z00_WDT_FLIGHTLIST_CONFIG'.
      target_view_name      = 'MAIN'.
      source_plug_name      = 'OUT_PLUG8'.
    when 9.
      target_component_name = 'Z00_WDT_FLIGHTLIST_EDIT'.
      target_view_name      = 'MAIN'.
      source_plug_name      = 'OUT_PLUG9'.
    when 10.
      target_component_name = 'Z00_WDT_FLIGHTLIST_EVENTS'.
      target_view_name      = 'MAIN'.
      source_plug_name      = 'OUT_PLUG10'.
    when 11.
      target_component_name = 'Z00_WDT_FLIGHTLIST_DYN'.
      target_view_name      = 'MAIN'.
      source_plug_name      = 'OUT_PLUG11'.
    when 12.
      target_component_name = 'Z_SE16_WDA'.
      target_view_name      = 'MAIN_VIEW'.
      source_plug_name      = 'OUT_PLUG12'.
    when others.
      target_component_name = 'ZZ_00_SFLIGHT'.
      target_view_name      = target_component_name.
  endcase.

  if node_index = 6.
    l_api_main = wd_this->wd_get_api( ).
    try.
        l_api_main->do_dynamic_navigation(
            source_window_name        = 'MAIN'
            source_vusage_name        = 'MAIN_VIEW_USAGE_1'
            source_plug_name          = source_plug_name
            target_view_name          = target_view_name
            target_plug_name          = 'DEFAULT'
            target_embedding_position = 'MAIN_VIEW/VIEW_CONTAINER').
        .
      catch cx_wd_runtime_repository .
        raise exception type cx_wdr_rt_exception.
    endtry.
  else.
    l_api_main = wd_this->wd_get_api( ).
    try.
        l_api_main->do_dynamic_navigation(
            source_window_name        = 'MAIN'
            source_vusage_name        = 'MAIN_VIEW_USAGE_1'
            source_plug_name          = source_plug_name
            target_component_name     = target_component_name
            target_view_name          = target_view_name
            target_plug_name          = 'DEFAULT'
            target_embedding_position = 'MAIN_VIEW/VIEW_CONTAINER').
        .
      catch cx_wd_runtime_repository .
        raise exception type cx_wdr_rt_exception.
    endtry.
  endif.
endmethod.

Answers (2)

Answers (2)

Former Member
0 Kudos

Hey Arjun, hey Thomas,

Thomas' version, a bit modiefied, in combination with example component WDR_TEST_DYNAMIC worked for me.

Thanks a lot for your answers, guys!

Steffi

arjun_thakur
Active Contributor
0 Kudos

Hi Stefanie,

You can also proceed in this way:

First create a main view which should be your default view. Put a Viewcontainer UI element in it.

Now create other views (which you want to display in that viewcontainer).

Embed all the other view in the viewcontainer. and create plugs from your main (default) view to every other view.

Now in the WDDOINIT method of the main view, just check your condition and fire the appropriate plug accordingly.

I hope it helps.

Regards

Arjun