!--a11y-->
Using External Context Mapping 
At design time, a Web Dynpro component does not know the context structures of its embedding Web Dynpro component. Therefore, it is not possible at design time to map context elements in the component interface controller of Web Dynpro component A to context elements that belong to a controller context of Web Dynpro component B, which has declared a usage of A. However, if Web Dynpro component A itself uses another Web Dynpro component within itself, this is possible (general context mapping).
There are many cases in which it is desirable for a Web Dynpro component to refer to context elements (context mapping) that belong to a controller context of its user. This method of data retrieval within a Web Dynpro component is provided by External Context Mapping (external context mapping cannot be used for value attributes that are directly inferior to the root node). During the development of a Web Dynpro component, external context mapping does not directly declare context mapping to an outer user, but declares the possibility of a subsequent general context mapping from a concrete component usage to its user.
To clarify this, consider the following graphic:
(1) |
The Internal Web Dynpro component is used by the Embedder Web Dynpro component. The original data is stored in the component controller context of Embedder. To be able to access this data from within a Web Dynpro component of type Internal, the corresponding context elements must first be declared as “mappable” in the context of the component interface controller. To do this, the element property isInputElement is set to true. |
(2) |
To display this data in a view of Internal, its context is mapped in the usual way to the context of the component interface controller. |
(3) |
The outer Web Dynpro component Embedder now uses the Internal Web Dynpro component by means of a concrete component usage named InternalComponent. |
(4) |
Its context in the component interface controller can be mapped in the outer Web Dynpro component using general context mapping to context elements in the component controller. |
(5) |
The component controller context keeps the original data; all other contexts use context mapping to refer to it. |
...
In our example, we want the inner Web Dynpro component to display in its view the running number of the currently visible instance. This information is, of course, known only to the embedding Web Dynpro component, which is responsible for creating and deleting such component instances. The inner Web Dynpro component must access this information using external context mapping.

The numbers in parentheses at the end of individual headings refer to the list underneath the above graphic.
...
1. In the Web Dynpro Explorer, select the node WebDynpro_Eventing ® Web Dynpro ® Web Dynpro Components ® Internal ® Component Interface ® Component Interface Controller.
2. Switch to the Context perspective view.
3. Add the following two context elements:
Context Element |
Property |
Value |
|
Cardinality |
1..1 |
|
isInputElement |
true |
|
isInputElement |
true |
|
Type |
integer |

The property isInputElement=true is used to declare a context element as mappable to the outside. As soon as the Web Dynpro component is used by an embedder, the actual context mapping must be declared to a context that is visible then.
4. Switch to the Context perspective view of the Form view.
5. Add a value node and call it OuterData:
Context Element |
Property |
Value |
|
Cardinality |
1..1 |
6. Choose Edit Context Mapping… to define the context mapping of this value node. Together with the corresponding value attribute, map it to the context elements with the same names in the component interface controller:
Context Element |
Property |
Value |
(Value node) |
Mapping – mappingRef |
InternalInterface.OuterData |
(Value attribute) |
Mapping – mappingRef |
InternalInterface.OuterData.Counter |
7. Enhance the layout of the Form view by the display of the counter variable that you access using external context mapping. Insert the UI elements listed in the table into the FormGroup group.
Property |
Value |
Label CounterLabel of type Label |
|
Properties of Label – layoutdata |
MatrixHeadData |
Properties of Label – text |
Number of Component Creations: |
Text CounterText of type TextView |
|
Properties of TextView – layoutdata |
MatrixData |
Properties of TextView – text |
|
Text InfoText of type TextView |
|
Properties of TextView – layoutdata |
MatrixHeadData |
Properties of TextView – text |
(Counter information received from outer component using external context mapping) |
LayoutData - colSpan |
3 |
In the next step, declare the context of the component controller of the embedding Web Dynpro component, in which to store the original data (to be more exact, a single value attribute).
8. In the Web Dynpro Explorer, select the node WebDynpro_Eventing ® Web Dynpro ® Web Dynpro Components ® Embedder ® Component Controller. Switch to the Context perspective view.
9. In the Context perspective view, declare the following context elements:
Context Element |
Property |
Value |
|
Cardinality |
1..1 |
|
Type |
integer |
10. In the Web Dynpro Explorer, select the node WebDynpro_Eventing ® Web Dynpro ® Web Dynpro Components ® Embedder ® Used Web Dynpro Components ® InternalComponent Interface Controller. You are now within the declared creation InternalComponent of type Internal Web Dynpro component, embedded into its user named Embedder.
11. Choose Add to add the following entry under Required Controllers: Embedder –com.sap.tc.webdynpro.tutorials.eventing.embedder; you need this entry to be able to define the context mapping for the component controller context.
12. Switch to the Context perspective view.
13. Define the context mapping between the component interface controller of the used Web Dynpro component called InternalInterface and the component controller of the embedding Web Dynpro component called Embedder.
Context Element |
Property |
Value |
(Value node) |
Mapping – mappingRef |
Embedder.DataSource |
(Value attribute) |
Mapping – mappingRef |
Embedder.DataSource.Counter |
14. Switch to the Properties perspective view of the ControlPanel view.
15. Under Required Controllers, use the Add button to add the following entry: Embedder – com.sap.tc.webdynpro.tutorials.eventing.embedder. This enables you to access the context of the component controller in the view controller.
16. Switch to the Implementation perspective view of the ControlPanel view.
17. In the onActionCreateComponent() method of the ControlPanel view controller, add the following source code:
//@@begin javadoc:onActionCreateComponent(ServerEvent) /** declared validating event handler */ //@@end public void onActionCreateComponent( com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent ) { //@@begin onActionCreateComponent(ServerEvent) wdThis.wdGetInternalComponentComponentUsage().createComponent();
// Set status of Action objects. Button events bound to these actions are // accordingly enabled or disabled. wdThis.wdGetCreateComponentAction().setEnabled(false); wdThis.wdGetDestroyComponentAction().setEnabled(true);
// Increment counter variable for component creations. The original // counter data is stored in the component controller context // (Embedder component). The internal component gets this counter using // external context mapping. int i = wdThis.wdGetEmbedderController().wdGetContext() .currentDataSourceElement().getCounter(); wdThis.wdGetEmbedderController().wdGetContext() .currentDataSourceElement().setCounter(++i); //@@end } |
18. In the Web Dynpro Explorer, select the node WebDynpro_Eventing ® Web Dynpro ® Web Dynpro Components ® Embedder ® Component Controller. Switch to the Implementation perspective view.
19. Initialize the Counter value attribute in the method wdDoInit() of the Embedder component controller:
//@@begin javadoc:wdDoInit() /** Hook method called to initialize controller. */ //@@end public void wdDoInit() { //@@begin wdDoInit() wdContext.currentDataSourceElement().setCounter(0); //@@end } |
In the enhanced Eventing example application, the Form view now additionally displays the number of component creations created so far by the ControlPanel view. The information is stored as a value attribute in the component controller of the embedding component. The inner component refers to this value attribute in its component interface context using External Context Mapping.

