!--a11y-->
Dynamically Embedding an Interface
View 
An interface view of a dynamically embedded component must be included dynamically into the navigation of a window. You can implement this, for example, in a method of the controller of the view that launches the navigation. The code fragment below shows the instanciation of the dynamically embedded component.
data: L_VIEW_CONTROLLER_API type ref to IF_WD_VIEW_CONTROLLER, L_COMPONENT_USAGE type ref to IF_WD_COMPONENT_USAGE, COMPONENT_NAME type STRING.
if L_COMPONENT_USAGE->HAS_ACTIVE_COMPONENT( ) is initial. L_COMPONENT_USAGE->CREATE_COMPONENT( COMPONENT_NAME ). endif.
|
Then the method PREPARE_DYNAMIC_NAVIGATION of the runtime API of the view controller is called. All attributes of the own – that is, the using – component are known and can be implemented statically (source attributes). All attributes of the used component are unknown at design time and are passed as variables (target attributes, values are displayed as placeholders in pointed brackets).
L_VIEW_CONTROLLER_API = WD_THIS->WD_GET_API( ). L_VIEW_CONTROLLER_API->PREPARE_DYNAMIC_NAVIGATION( source_window_name = 'W0' source_vusage_name = 'MAIN_USAGE_1' source_plug_name = 'TO_V1' target_component_name = <component_name> target_component_usage = <component_usage_name> target_view_name = <interface_view_name> target_plug_name = <inbound_plug_name> target_embedding_position = <embedding_position> ).
|
The method PREPARE_DYNAMIC_NAVIGATION of the API of the view controller embeds the interface view <interface_view_name> of component <component_name> at the respective embedding position <embedding_position> (see below). In addition, a navigation link is created from the outbound plug TO_V1 of the view MAIN to the inbound plug <inbound_plug_name> of the interface view <interface_view_name>. The component specified in <component_name> must implement the component interface to which the component usage <component_usage_name> points.
In the last step of this fragment, the outbound plug is called.
WD_THIS->FIRE_TO_V1_PLG( ). . .
|
In the example application WDR_TEST_DYNAMIC the component interface
WDR_TEST_DYNAMIC_CI is implemented by the components WDR_TEST_DYNAMIC_1,
WDR_TEST_DYNAMIC_2 and WDR_TEST_DYNAMIC_3.
Note that the method PREPARE_DYNAMIC_NAVIGATION must be called in the phase model up to
and including the phase DO_BEFORE_NAVIGATION, ideally in an action
handler, because otherwise no navigation will take place.
When embedding the interface view, different cases may be of relevance:
1. To embed the interface view directly into a window of the using component, no further steps are required. By specifying the value for the attribute <embedding_position>, the display of the interface view within the selected window is triggered automatically.
2.

3. However, if you want to display the interface view in a view within the window of the using component, the interface view is considered in the rendering process only if it has been positioned in a view container element within the embedding view:

This view container element can exist in the embedding view if it has been declared statically. In this case, the embedded interface view will also be displayed automatically and together with the embedding view after specifying the view container element as the value for the embedding position in method PREPARE_DYNAMIC_NAVIGATION.
4. However, it may also occur that the view container must be created dynamically at runtime. The code fragment below shows an example for creating such an additional container, which must always be programmed in the method WDDOMODIFYVIEW of the respective view:
data: L_ROOT_CNT type ref to CL_WD_UIELEMENT_CONTAINER, L_VIEW_CNT type ref to CL_WD_VIEW_CONTAINER_UIELEMENT, L_MATRIX_HEAD_DATA type ref to CL_WD_MATRIX_HEAD_DATA.
if first time = abap_true. L_ROOT_CNT ?= VIEW->GET_ELEMENT( ’ROOTUIELEMENTCONTAINER’ ).
L_VIEW_CNT = CL_WD_VIEW_CONTAINER_UIELEMENT=>NEW_VIEW_CONTAINER_UIELEMENT( ID = ‘CNT1’ ).
L_ROOT_CNT->ADD_CHILD( L_VIEW_CNT ).
L_MATRIX_HEAD_DATA = CL_WD_MATRIX_HEAD_DATA=>NEW_MATRIX_HEAD_DATA( ELEMENT = L_VIEW_CNT ). endif. |
The name of the dynamically created view
container element is passed to method PREPARE_DYNAMIC_NAVIGATION (see above)
even though the element will be created only at a later point in time in the
phase model.