Professional Documents
Culture Documents
Summary
This document provides detailed instructions on how to use Web Dynpro Component Interfaces in a Web Dynpro Java Application. It contains step-by-step instructions for creating the component interface definition and implementing this interface definition in the Web Dynpro component.
Author(s): Mahesh K. Company: LARSEN & TOUBRO INFOTECH Ltd. Created on: 28 March 2007
Author Bio
Mahesh K. is a SAP NetWeaver (Web Application Development Focus JAVA) certified Technical Consultant working with L&T Infotech, Mumbai, India. His SAP experience of over 2 years spans various technologies such as ABAP, Web Dynpro for Java and Enterprise Portal.
Table of Contents
Using Web Dynpro Component Interface Definition........................................................................ 1 Applies to: ........................................................................................................................................ 1 Summary.......................................................................................................................................... 1 Author Bio ........................................................................................................................................ 1 Table of Contents ............................................................................................................................ 2 Introduction ...................................................................................................................................... 3 Project Structure .............................................................................................................................. 4 Creating the Component Interface Definition .................................................................................. 5 Implementing the Component Interface Definition .......................................................................... 7 Making Use of Component Interface Definition ............................................................................. 10 Result............................................................................................................................................. 15 Related Content............................................................................................................................. 16 Disclaimer and Liability Notice....................................................................................................... 16
Introduction
Consider a scenario wherein there is a main component and two child components. We have to decide at runtime which component instance has to be displayed in the main component. Developing two monolithic components would mean that one has to reference both the child component instances in the main component. As an alternative we can make use of Component Interface Definition. Component Interface Definition gives an abstract definition of the UI component interfaces (component interface controller and component interface views). Process involves creating a root component interface with an interface view and then implementing this interface definition in both child components. In main component we need to reference the component instance of the root component interface only. Context variables, methods and events can also be reused in different components by defining it in the interface definition. The following example will illustrate the use of these interface definition and the reuse of methods and the interface views in different components. It will also show how to create component instance at runtime using IWDComponentUsage.
Project Structure
The project DP_TutWDInterfaces consist of 3 components of the following name: TutWDUInterfacesComp (Main component) ChldDC1Comp ChildDC2Comp
Name Component View Window <Component Name>Comp <Component Name>CompView <Component Name>CompWin
Package Assignment com.sap.wd.<Component Name>comp com.sap.wd.< Component Name >compview com.sap.wd.< Component Name >compwin
After creating the components delete the default window for the following components ChldDC1Comp ChildDC2Comp
as shown below
Name WDCompInterf
Package com.sap.wd.wdcompinterf
Right click on Interface View Definitions and create an Interface View as shown below
Name ChildDCCompWin
Package com.sap.wd.wdcompinterf
It will create a window with the same name as that of the interface view created in the Interface definition as shown below
Embed the existing view of the component in this window. Double click on the component interface controller of the component. You can see the method passInfo implemented in it.
Go to the implementation tab and inside the method passInfo, write the following code //@@begin javadoc:passInfo() /** Declared method. */ //@@end public void passInfo( java.lang.String p_Msg ) { //@@begin passInfo() // Set the context variable with the text passed through p_Msg wdContext.currentContextElement().setMsg(p_Msg); //@@end }
Open the ChildDC2CompView and click on the properties tab. Add the component interface controller under the required controllers
Map the context variable Msg from the component Interface Controller to the View.
Go to the layout of the view and insert a TextView element and bind it to the context variable Msg
Create actions for the buttons btn_DC1 ( Create Child DC 1 ) btn_DC2 ( Create Child DC 2 )
Button ID btn_DC1
Action createDC1
btn_DC2
createDC2
onActioncreateDC2
Open the Navigation Modeler of the component and right click on the ViewContainerUIElement to embed the interface view of the component interface definition.
Select the option Embed Interface View of a Component Instance since we are using the interface view of the component interface definition added under the used components.
Select the required interface view from the list as shown below.
After adding the interface view the window will be as shown below.
Go to the properties tab of TutWDInterfacesCompView and add WDCompInterfInst (Web Dynpro component usage) under required controller(s) of the view.
Then click the implementation tab of the view and add the following code /* * The following code section can be used for any Java code that is * not to be visible to other controllers/views or that contains constructs * currently not supported directly by Web Dynpro (such as inner classes or * member variables etc.). </p> * * Note: The content of this section is in no way managed/controlled * by the Web Dynpro Designtime or the Web Dynpro Runtime. */ //@@begin others IWDComponentUsage g_Usage = null; //@@end
//@@begin javadoc:wdDoInit() /** Hook method called to initialize controller. */ //@@end public void wdDoInit() { //@@begin wdDoInit() g_Usage = wdThis.wdGetWDCompInterfInstComponentUsage(); //@@end }
//@@begin javadoc:onActioncreateDC1(ServerEvent) /** Declared validating event handler. */ //@@end public void onActioncreateDC1(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent ) { //@@begin onActioncreateDC1(ServerEvent) // Check if there is a active component of WDCompInterfInst if (g_Usage.hasActiveComponent() == true) { // Delete the active component g_Usage.deleteComponent(); } // Check if there is a active component of WDCompInterfInst if (!g_Usage.hasActiveComponent()) { // If no active component is there, then create the component g_Usage.createComponent("com.sap.wd.childdc1comp.ChldDC1Comp"); wdThis.wdGetWDCompInterfInstInterface().passInfo( "Created Child DC 1"); } //@@end }
//@@begin javadoc:onActioncreateDC2(ServerEvent) /** Declared validating event handler. */ //@@end public void onActioncreateDC2(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent ) { //@@begin onActioncreateDC2(ServerEvent) // Check if there is a active component of WDCompInterfInst if (g_Usage.hasActiveComponent() == true) { // Delete the active component g_Usage.deleteComponent(); } // Check if there is a active component of WDCompInterfInst if (!g_Usage.hasActiveComponent()) { // If no active component is there, then create the component g_Usage.createComponent("com.sap.wd.childdc2comp.ChildDC2Comp"); wdThis.wdGetWDCompInterfInstInterface().passInfo( "Created Child DC 2"); } //@@end }
Result
When we the run the application the following window opens up in the internet browser
When we click on button Create Child DC1, the child component DC1 is created and a message displayed as shown below
When we click on button Create Child DC2, the child component DC2 is created and a message displayed as shown below
Related Content
Web Dynpro Component Interface Definitions in Practice The Structural Concepts of Web Dynpro Components