creating component definition

Upload: soumyojit2013

Post on 14-Apr-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/29/2019 Creating Component Definition

    1/16

    WDJ - Using Web Dynpro Component Interface Definition

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 1

    WDJ - Using Web Dynpro Component Interface Definit ion

    Appl ies to:SAP WAS SP 16

    Summary

    This document provides detailed instructions on how to use Web Dynpro Component Interfaces in a WebDynpro Java Application. It contains step-by-step instructions for creating the component interface definitionand 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) certifiedTechnical Consultant working with L&T Infotech, Mumbai, India. His SAP experience of over 2years spans various technologies such as ABAP, Web Dynpro for Java and Enterprise Portal.

  • 7/29/2019 Creating Component Definition

    2/16

    WDJ - Using Web Dynpro Component Interface Definition

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 2

    Table of Contents

    Using Web Dynpro Component Interface Definition........................................................................ 1Applies to: ........................................................................................................................................ 1Summary.......................................................................................................................................... 1

    Author Bio ........................................................................................................................................ 1Table of Contents ............................................................................................................................ 2Introduction ...................................................................................................................................... 3Project Structure .............................................................................................................................. 4Creating the Component Interface Definition .................................................................................. 5Implementing the Component Interface Definition .......................................................................... 7Making Use of Component Interface Definition ............................................................................. 10Result............................................................................................................................................. 15Related Content............................................................................................................................. 16Disclaimer and Liability Notice....................................................................................................... 16

  • 7/29/2019 Creating Component Definition

    3/16

    WDJ - Using Web Dynpro Component Interface Definition

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 3

    Introduction

    Consider a scenario wherein there is a main component and two child components. We have to decide atruntime which component instance has to be displayed in the main component. Developing two monolithiccomponents would mean that one has to reference both the child component instances in the maincomponent.

    As an alternative we can make use of Component Interface Definition. Component Interface Definition givesan abstract definition of the UI component interfaces (component interface controller and componentinterface views). Process involves creating a root component interface with an interface view and thenimplementing this interface definition in both child components. In main component we need to reference thecomponent instance of the root component interface only.

    Context variables, methods and events can also be reused in different components by defining it in theinterface definition. The following example will illustrate the use of these interface definition and the reuse ofmethods and the interface views in different components. It will also show how to create component instanceat runtime using IWDComponentUsage.

  • 7/29/2019 Creating Component Definition

    4/16

    WDJ - Using Web Dynpro Component Interface Definition

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 4

    Project Structure

    The project DP_TutWDInterfaces consist of 3 components of the following name:

    TutWDUInterfacesComp (Main component)

    ChldDC1Comp

    ChildDC2Comp

    Name Package Assignment

    Component Comp com.sap.wd.comp

    View CompView com.sap.wd.< Component Name >compview

    Window CompWin com.sap.wd.< Component Name >compwin

    After creating the components delete the default window for the following components

    ChldDC1Comp

    ChildDC2Comp

    as shown below

  • 7/29/2019 Creating Component Definition

    5/16

    WDJ - Using Web Dynpro Component Interface Definition

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 5

    Creating the Component Interface Definit ion

    Right click on the Web Dynpro Component Interfaces and create the component interface definition asshown below

    Name Package

    WDCompInterf com.sap.wd.wdcompinterf

    Click on the methods tab and create a method passInfo

    Method Name Return type

    passInfo void

    Parameter Name Return type

    p_Msg string

    Click on the context tab and create a context variable Msg

  • 7/29/2019 Creating Component Definition

    6/16

    WDJ - Using Web Dynpro Component Interface Definition

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 6

    Right click on Interface View Definitions and create an Interface View as shown below

    Name Package

    ChildDCCompWin com.sap.wd.wdcompinterf

  • 7/29/2019 Creating Component Definition

    7/16

    WDJ - Using Web Dynpro Component Interface Definition

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 7

    Implementing the Component Interface Definition

    Components ChldDC1Comp and ChildDC2Comp will be implementing the component interfacewdCompInterf.

    Go to the Implement Interfaces part ofChildDC2Comp and right click on it to implement the interfacedefinition as shown below

  • 7/29/2019 Creating Component Definition

    8/16

    WDJ - Using Web Dynpro Component Interface Definition

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 8

    It will create a window with the same name as that of the interface view created in the Interface definition asshown 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 passInfoimplemented in it.

    Go to the implementation tab and inside the method passInfo, write the following code

    / / @@begi n j avadoc: passI nf o( ) / ** Decl ared met hod. */

    d/ / @@en public void passI nf o( j ava. l ang. St r i ng p_Msg ){

    / / @@begi n passI nf o( ) / / Set t he cont ext var i abl e wi t h t he t ext passed t hr ough p_MsgwdCont ext . cur r ent Cont ext El ement ( ) . set Msg(p_Msg) ;

    / / @@end

    }

    Open the ChildDC2CompView and click on the properties tab. Add the component interface controller underthe required controllers

  • 7/29/2019 Creating Component Definition

    9/16

    WDJ - Using Web Dynpro Component Interface Definition

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 9

    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

    Repeat the same process for the component ChldDC1Comp.

  • 7/29/2019 Creating Component Definition

    10/16

    WDJ - Using Web Dynpro Component Interface Definition

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 10

    Making Use of Component Interface Definition

    TutWDInertacesComp is the main component through which we display both the child components.So add the component interface definition under the used components ofTutWDInterfacesComp

    Open the layout ofTutWDInterfacesCompView and add UI elements as shown below.

  • 7/29/2019 Creating Component Definition

    11/16

    WDJ - Using Web Dynpro Component Interface Definition

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 11

    Create actions for the buttons

    btn_DC1 ( Create Child DC 1 )

    btn_DC2 ( Create Child DC 2 )

    Button ID Action Event Handler

    btn_DC1 createDC1 onActioncreateDC1

    btn_DC2 createDC2 onActioncreateDC2

    Open the Navigation Modelerof the component and right click on the ViewContainerUIElement to embedthe interface view of the component interface definition.

    Select the option Embed Interface View of a Component Instance since we are using the interface view ofthe component interface definition added under the used components.

  • 7/29/2019 Creating Component Definition

    12/16

    WDJ - Using Web Dynpro Component Interface Definition

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 12

    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 componentusage) under required controller(s) of the view.

  • 7/29/2019 Creating Component Definition

    13/16

    WDJ - Using Web Dynpro Component Interface Definition

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 13

    Then click the implementation tab of the view and add the following code

    / ** The f ol l owi ng code sect i on can be used f or any J ava code that i s* not t o be vi si bl e t o ot her cont r ol l er s/ vi ews or t hat cont ai ns const r uct s

    * cur r ent l y not support ed di r ect l y by Web Dynpr o ( such as i nner cl asses or* member var i abl es et c. ) . ** Note: The cont ent of t hi s sect i on i s i n no way managed/ cont r ol l ed* by t he Web Dynpro Desi gnt i me or t he Web Dynpro Runt i me.*/

    / / @@begi n ot her sI WDComponent Usage g_Usage = null;

    / / @@end

    / / @@begi n j avadoc: wdDoI ni t ( ) / ** Hook met hod cal l ed t o i ni t i al i ze cont rol l er . */

    d/ / @@en public void wdDoI ni t ( ){

    / / @@begi n wdDoI ni t ( ) g_Usage = wdThi s. wdGet WDCompI nt er f I nst ComponentUsage( ) ;

    / / @@end

    }

    / / @@begi n j avadoc: onAct i oncr eat eDC1(Ser ver Event ) / ** Decl ared val i dat i ng event handl er . */

    / / @@end

    public voidonAct i oncr eat eDC1(com. sap. t c. webdynpr o. progmodel . api . I WDCust omEvent wdEvent )

    {/ / @@begi n onAct i oncr eat eDC1(Ser verEvent )

    / / Check i f t her e i s a act i ve component of WDCompI nt er f I nst if ( g_Usage. hasAct i veComponent ( ) == true) {

    / / Del ete the act i ve component g_Usage. del et eComponent ( ) ;

    }Check i f t her e i s a act i ve component of WDCompI nt er f I nst / /

    if ( ! g_Usage. hasAct i veComponent ( ) ) {/ / I f no act i ve component i s t here, t hen cr eat e t he component

    g_Usage. cr eat eComponent ( "com. sap. wd. chi l ddc1comp. Chl dDC1Comp") ;wdThi s. wdGet WDCompI nt er f I nst I nt erf ace( ) . passI nf o(

    "Cr eat ed Chi l d DC 1") ;}

    / / @@end

    }

  • 7/29/2019 Creating Component Definition

    14/16

    WDJ - Using Web Dynpro Component Interface Definition

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 14

    / / @@begi n j avadoc: onAct i oncr eat eDC2(Ser ver Event ) / ** Decl ared val i dat i ng event handl er . */

    / / @@endpublic void

    onAct i oncr eat eDC2(com. sap. t c. webdynpr o. progmodel . api . I WDCust omEvent wdEvent ){

    / / @@begi n onAct i oncr eat eDC2(Ser verEvent )

    / / Check i f t her e i s a act i ve component of WDCompI nt er f I nst if ( g_Usage. hasAct i veComponent ( ) == true) {

    / / Del ete the act i ve component g_Usage. del et eComponent ( ) ;

    }/ / Check i f t her e i s a act i ve component of WDCompI nt er f I nst if ( ! g_Usage. hasAct i veComponent ( ) ) {

    / / I f no act i ve component i s t here, t hen cr eat e t he component

    g_Usage. cr eat eComponent ( "com. sap. wd. chi l ddc2comp. Chi l dDC2Comp") ;wdThi s. wdGet WDCompI nt er f I nst I nt erf ace( ) . passI nf o(

    "Cr eat ed Chi l d DC 2") ;}/ / @@end

    }

    Then deploy and run the application.

  • 7/29/2019 Creating Component Definition

    15/16

    WDJ - Using Web Dynpro Component Interface Definition

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 15

    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 displayedas shown below

    When we click on button Create Child DC2, the child component DC2 is created and a message displayedas shown below

  • 7/29/2019 Creating Component Definition

    16/16

    WDJ - Using Web Dynpro Component Interface Definition

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com

    2007 SAP AG 16

    Related Content

    Web Dynpro Component Interface Definitions in Practice

    The Structural Concepts of Web Dynpro Components

    Disclaimer and Liabili ty Notice

    This document may discuss sample coding or other information that does not include SAP official interfacesand therefore is not supported by SAP. Changes made based on this information are not supported and canbe overwritten during an upgrade.

    SAP will not be held liable for any damages caused by using or misusing the information, code or methodssuggested in this document, and anyone using these methods does so at his/her own risk.

    SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content ofthis technical article or code sample, including any liability resulting from incompatibility between the contentwithin this document and the materials and services offered by SAP. You agree that you will not hold, or

    seek to hold, SAP responsible or liable with respect to the content of this document.

    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/f07c3625-c971-2910-3a9c-ce131487f82chttps://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/a048387a-0901-0010-13ac-87f9eb649381https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/a048387a-0901-0010-13ac-87f9eb649381https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/f07c3625-c971-2910-3a9c-ce131487f82c