• No results found

Web Dynpro Component Interfaces

In document NET311 Advanced ABAP Web Dynpro (Page 98-105)

The interface of a Web Dynpro component consists of the interface controller and as many interface views as windows are defined in the component.

The functionality of the interface controller is defined in the component controller.

The developer can set the flag INTERFACE for ordinary methods, events, and context nodes, so these controller parts appear in the interface controller. For a context node an additional property (Input Element (ext)) allows to prepare this context node for external context mapping.

The functionality of an interface view is defined in the related window. Only the window's plugs can be defined in the interface view (flag INTERFACE). For the consumer component, embedding an interface view of a used component in a ViewUIElementContainer does not differ from embedding a view defined in the own component.

Figure 57: The interface of a Web Dynpro component

The repository object type Web Dynpro component interface allows to define component entities to be contained in a component's interface as a separate object. A component interface may be implemented by an arbitrary number of Web Dynpro components, resulting in a common set of methods, events, context nodes and interface views existing for all these components. On the other side, any Web Dynpro component can implement an arbitrary number of Web Dynpro component interfaces. In this case, the component implementing the component interfaces will containing all methods, events, context nodes and interface views defined in any of the component interfaces.

Creating a Web Dynpro Component Interface

From the context menu of a package, a Web Dynpro component interface can be created via the menu item Create → Web Dynpro → Web Dynpro Component (Interface). In the dialog box appearing, the radio button having the description Web Dynpro Component Interface has to be selected. After having saved the component interface, a new entry appears in node Web Dynpro Comp. Interfaces of the object tree for the related package. After creation, the component interface contains an interface controller but no interface views. However, from the context menu for the component interface, an arbitrary number of interface views can be created.

Figure 58: Creating a component interface

Figure 59: Web Dynpro component interface: Creating an interface view

Implementing Web Dynpro Component Interfaces by Web Dynpro Components

To implement a Web Dynpro component interface by a component, the name of the component interface has to entered in column Name on tab Implemented Interfaces of the implementing component. After having pressed Enter, a red light appears and a button with the label Reimplement. Pressing this button will do the following:

• Methods, events, and context nodes defined in the interface controller of the component interface are copied to the component controller of the implementing component.

• From the interface view defined in the component interface, a window will be generated in the implementing component.

Hint: If a component interface is implemented by a component, the flag INTERFACE available for all entities of a component interface is not set automatically.

Hint: Implementing a component interface means copying the related entities. If methods, events, context nodes, or interface views are deleted in the component interface, they are not deleted in the implementing components. However, if the method's signatures are changed or if entities are added to the component interface the implementation has to be actualized in all implementing components.

Hint: Deleting the implementation of a component interface does not delete the entities from the implementing component.

Figure 60: Implementing Web Dynpro component interfaces by Web Dynpro components

Instantiating Usages of Components having implemented the same Component Interface

In this section component reuse is discussed under the following boundary conditions:

• Multiple components that may be reused by a consumer component have implemented the same component interface. Only one of these components is reused at the same time.

• The consumer component only needs to access functionality defined in the implemented component interface.

In this case, the consumer component does not need to define a separate component usage for each of the possible sub components, but only one usage of the implemented component interface. Which one of the possible sub components is to be instantiated can then be decided at runtime.

Figure 61: Reusing components having implemented the same component interface (1)

Each controller having added the usage of the interface component to its list of used components / controllers can instantiate the usage of a component, that has implemented the component interface. However, since the name of the component is not fixed, it is necessary to pass the components name to the method used to instantiate the component usage.

Hint: All entities of a component that are defined in the implemented interface can be accessed by the consumer component, if the consumer component accesses this sub component via a usage of the implemented component interface. It is not necessary to set the flag INTERFACE for these entities in the implementing component.

Figure 63: Instantiation of a component usage implementing a given component interface

This technique also allows to define the component to be used at runtime dynamically (e.g. via configuration). Thus, components not known at design time can be reused and the related interface view can be embedded as long as they implement a given interface controller. It is also possible to exchange the used component at runtime by first deleting the existing instance of the component usage and then instantiate a different component usage using the same reference to the commonly implemented component interface.

Figure 64: Exchanging used components implementing the same component interface

All entities defined in the component interface are always visible to the consumer component having defined the component interface as a used component.

This does not depend on having the flag INTERFACE set in the implementing component!

However, if the component implementing the interface is added to the list of used components, this flag works as expected. Only those entities of the implemented component interface are visible to the consumer component that have the flag INTERFACE set.

In document NET311 Advanced ABAP Web Dynpro (Page 98-105)