creating email client

Upload: soumyojit2013

Post on 14-Apr-2018

228 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/29/2019 Creating Email Client

    1/25

    Creating an E-Mail Client Using Web Dynpro's Adaptive Web Service Model

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

    2006 SAP AG 1

    Creating an E-Mail Client Using Web Dynpro's Adaptive WebService Model

    Appl ies to:

    Web Dynpro for Java UI Development, SAP NetWeaver 04 SP Stack 17, SAP NetWeaver 04s SP Stack 6

    Summary

    In this tutorial, you will develop a Web Dynpro application for sending an e-mail message, using an e-mailWeb service provided by an external service provider. It fully describes all required development steps likesetting up a new project, importing theAdaptive Web Service Model, defining context mapping and bindingrelations, designing the view layout and implementing the controller code.

    Use of the e-mail Web service is enabled by an appropriateAdaptive Web Service model generated by theWeb Dynpro tools. The quick implementation of this Web Dynpro application is characterized by a highlydeclarative development process, in which the required implementation workload can be reduced to a fewlines of Java code.

    Note

    This tutorial covers the basic principles ofUsing the new Adaptive Web Service Model within a Web DynproJava application.You can read more advanced technical details on the coding-specific aspects in the relatedSDN articleAdaptive Web Service Model Controller Coding Explained. Both articles are based on the

    same Web Dynpro sample application.

    Author: Bertram Ganz

    Company: SAP AG

    Created on: 21 February 2007

    Author Bio

    After his studies in mathematics, physics and computer science Bertram Ganz finished histeacher training at a German grammar school stressing technical sciences. He has been amember of the Web Dynpro Java Runtime development team (SAP NetWeaver ESIFoundation UI) since 2002. The main focus of his work is on knowledge transfer, rollout, anddocumentation. Bertram regularly publishes articles on Web Dynpro in the context of the SNetWeaver Application Server. Bertram is co-author of the books Maximizing Web Dynprfor Java and Java Programming with the Web Application Server.

    APo

    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/900bbf94-a7a8-2910-e298-a651b4706c1ehttps://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/900bbf94-a7a8-2910-e298-a651b4706c1e
  • 7/29/2019 Creating Email Client

    2/25

    Creating an E-Mail Client Using Web Dynpro's Adaptive Web Service Model

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

    2006 SAP AG 2

    Table of Contents

    Creating an E-Mail Client Using Web Dynpro's Adaptive Web Service Model ............................... 1

    Summary.......................................................................................................................................... 1

    Author Bio ........................................................................................................................................ 1

    Table of Contents ............................................................................................................................ 2

    Introduction ...................................................................................................................................... 3Whats New in SAP NetWeaver 04s ............................................................................................ 3

    Objectives .................................................................................................................................... 4

    Prerequisites ................................................................................................................................ 4

    Creating the Project Structure ......................................................................................................... 5

    Creating a Web Dynpro Project ................................................................................................... 5

    Creating a Web Dynpro application with a Web Dynpro component........................................... 5

    Result ........................................................................................................................................... 5

    Importing an Adaptive Web Service Model ..................................................................................... 7

    Importing a New Adaptive Web Service Model in a Component ................................................. 7Result ........................................................................................................................................... 9

    Defining Mapping and Binding Relations....................................................................................... 10

    Result ......................................................................................................................................... 12

    Mapping View Context Elements to Component Context Elements ............................................. 12

    Defining a Context Mapping in the Data Modeler ...................................................................... 12

    Result ......................................................................................................................................... 13

    Creating the SendEmail Action...................................................................................................... 14

    Result ......................................................................................................................................... 15

    Designing the View Layout ............................................................................................................ 15

    Creating a layout for the EmailFormView view .......................................................................... 15

    Data Binding to the View Context .............................................................................................. 18

    Binding Action to onAct i on Event of the UI Element SendButton ......................................... 18

    Implementing the Controller Code................................................................................................. 19

    Adding the Implementation for the Web Service Connection .................................................... 19

    Implementing the Method wdDoI ni t ( ) of the Component Controller ..................................... 19

    Implementing the public method sendEmai l ( ) in the Component Controller.......................... 20

    Implementing the Action Event HandleronAct i onSendEmai l ( ) .......................................... 21

    Result ......................................................................................................................................... 22

    Building, Deploying, and Running the Project ............................................................................... 22

    Building the Project .................................................................................................................... 22

    Deploying and Launching the Application.................................................................................. 22

    Result ......................................................................................................................................... 22

    Related Content............................................................................................................................. 24

    Copyright........................................................................................................................................ 25

  • 7/29/2019 Creating Email Client

    3/25

    Creating an E-Mail Client Using Web Dynpro's Adaptive Web Service Model

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

    2006 SAP AG 3

    Introduction

    In this tutorial, you will develop a Web Dynpro application for sending an e-mail message, using an e-mailWeb service provided by an external service provider.

    The user interface of this Web application is to consist of a simple input form for editing the addresses ofsenders and recipients, the subject, and the actual e-mail message, and a button for sending the message. Amessage is to be displayed in the Web browser to inform users of whether or not the e-mail message was

    successfully sent.Use of the e-mail Web service is enabled by an appropriateAdaptive Web Service model (model entity andmodel classes) generated by the Web Dynpro tools. At runtime, the data entered by the user of theapplication is passed to the model through the data binding between the input fields and the contextelements, and through the model binding of these context elements. The model communicates with the Webservice provider through the Web Dynpro Runtime and the Web Service Runtime as part of the SAPNetWeaver Application Server Java.

    Web Dynpro Runtime in NW Web AS Java

    Web Dynpro Component

    EmailFormView

    ControllerEmailFormView

    WindowComponent

    Controller

    Web

    Dynpro

    Client

    Adapt ive Emai l

    Web Service

    Model

    Email

    Web Service

    Provider

    SOAP/HTTP

    Web

    BrowserHTTP

    Model Usage

    The quick implementation of this Web Dynpro application is characterized by a highly declarativedevelopment process, in which the required implementation workload can be reduced to a few lines of Java

    code.

    Whats New in SAP NetWeaver 04s

    The newAdaptive Web Service Model was introduced in SAP NetWeaver 04 SP Stack 17 and SAPNetWeaver 04s SP Stack 6 replacing the former Web Service Model. The new Adaptive Web Service Modelprovides additional functions which yield the following advantages:

    Enhanced Web Service Model Implementation: Common Model Interface (CMI) implementation with a generic and a typed model class layer.

    Typed model classes are based on generic base and/or delegation classes so that bug fixes arepossible without requiring a new code generation.

    Improved support for WSDL and XML schema constructs with a better knowledge about givenlimitations

    Allow renaming of model classes during import Runtime settings are configurable at runtime through WS-Runtime configuration and logical Web

    Service destinations.

    Logical Web Service Destinations: Configuration of connection, authentication, encryption settings (not applied in this tutorial sample

    application)

  • 7/29/2019 Creating Email Client

    4/25

    Creating an E-Mail Client Using Web Dynpro's Adaptive Web Service Model

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

    2006 SAP AG 4

    NOTE: Currently Logical Web Service Destinations can only be defined for those Web Serviceproviders supporting WSIL (Web Service Inspection Language).

    Web Service Runtime Service Extension Interfaces: Modify HTTP, SOAP, security settings via API (e.g. to set non-SAP SSO cookie)

    Advanced Web Service Secur ity Suppor t Advanced security settings are supported via the Web Service Runtime Service Extension

    Interfaces

    Single-Sign-On support (SSO) Debugging and Tracing Support

    Tracing of model content ((model data and metadata) and SOAP traffic for problem analysis HTTP request/response for SOAP calls

    Objectives

    By the end of this tutorial, you will be able to:

    Create an Adaptive Web Service model to be used for connecting an external Web service from withinthe Web Dynpro project

    Declare a context node in the component controller and create a binding-relation to the model. Perform context mapping between the view controller and the component controller. Design a simple view layout for sending an e-mail message Create an action and implement an event handler Create the data binding from UI elements to context attributes Display the message texts in the Web Browser using a UI service provided by the Web Dynpro runtime

    environment

    Perform the implementation for availing of the e-mail Web service used.Prerequisites

    Systems, Installed Applications, and Authorizations

    You have installed SAP NetWeaver 04 SP 17 or SAP NetWeaver 04s SP 6 You have launched the SAP NetWeaver Developer Studio. You have access to the SAP J2EE Engine. You can connect to a database instance of the SAP DB. You have an open Internet connection. The service provider e-mail Web service used in the tutorial is available.

    SAP AG cannot guarantee the availability of the third-party Web service used in this tutorial and does notassume any responsibility for the quality of this service.

    Knowledge

    You have acquired some basic experience with Web Dynpro applications - for example, by workingthrough the Welcome Quickstart Guide (Creating Your First Web Dynpro Application).

    Basic knowledge of Java would be an advantage.

    https://www.sdn.sap.com/irj/sdn/downloaditem?rid=/library/uuid/979de990-0201-0010-429c-d1c522d8a32ahttps://www.sdn.sap.com/irj/sdn/downloaditem?rid=/library/uuid/979de990-0201-0010-429c-d1c522d8a32a
  • 7/29/2019 Creating Email Client

    5/25

    Creating an E-Mail Client Using Web Dynpro's Adaptive Web Service Model

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

    2006 SAP AG 5

    Creating the Project Structure

    You can now start creating the project structure that is the basis for the Web service example application. Toinclude all the development objects, first create a new Web Dynpro project. Add a new Web Dynprocomponent to this project that can be displayed in the Web Browser using the corresponding Web Dynproapplication.

    The following description does not list every single step in detail, since you have already become familiarwith a similar procedure in the Welcome Quickstart Guide.

    Execute the following steps so that you can continue afterwards with actually developing the Web Dynproexample application (view layout, connection to the public E-Mail Web service, data binding, contextstructures, model binding, and so on).

    Creating a Web Dynpro Project

    1. Choose File New Project Web Dynpro Project: The Web Dynpro Project wizard appears.

    2. Enter the project name TutWD_EmailAdWS and leave all the standard settings for the projectunchanged.

    Creating a Web Dynpro application with a Web Dynpro component

    3. To open the wizard, open the context menu for the Applications node and choose Create Application.

    4. Enter the name EmailAdWSApp for the Web Dynpro application and the package namecom.sap.tc.wd.adws.app.

    5. Accept the default setting (that is, Authentication is deselected) and Next.

    6. Select the radio button Create a new component and choose Next.

    7. Enter EmailAdWSComp as the name for this Web Dynpro component. Enter the package name

    com.sap.tc.wd.adws.comp.email and leave all the other default settings unchanged.

    8. Let the radio button Embed new View selected and give the new view the name EmailFormView.

    9. Choose Finish.

    Result

    You have now created the basic project structure for the new Web Dynpro project TutWD_EmailAdWS. Inthe Web Dynpro Explorer, the following nodes are displayed for the structure:

  • 7/29/2019 Creating Email Client

    6/25

    Creating an E-Mail Client Using Web Dynpro's Adaptive Web Service Model

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

    2006 SAP AG 6

    You have now made all the preparations necessary to develop the specific functions of the exampleapplication.

  • 7/29/2019 Creating Email Client

    7/25

    Creating an E-Mail Client Using Web Dynpro's Adaptive Web Service Model

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

    2006 SAP AG 7

    Importing an Adaptive Web Service Model

    Before you can use the e-mail Web service provided by an external provider within this Web Dynpro exampleapplication, you need to create the appropriate model. You will do this in the next step. At runtime, this modelperforms the data exchange between a Web Dynpro component and the Web service end point.

    Within a Web Dynpro component, business data is stored in separate context structures (consisting ofcontext nodes, context node elements, and context attributes). In this example, Subject, E-mail Text, Sender

    Address, and Recipient Address are the context attributes for the context node SendEmail. To transfer the e-mail information entered by the user to the Web service and to receive the response, you need a model thatholds business data in model objects and that communicates with the Web service provider through the WebDynpro Runtime and the Web Service Runtime as part of the SAP NetWeaver Application Server Java.

    You can use the Web Dynpro tools to generate such a model for a particular Web service description. Themodel mainly consists of special model classes to which you can bind model nodes and model attributes of acontroller context (model binding).

    The following is a description of how to generate a Web Dynpro model from the WSDL description of the e-mail Web service. (WSDL is an XML format used to describe network services.) This WSDL description ismade available by the service provider.

    SAP AG does not accept any responsibility regarding the availability and quality of the externale-mail service used in this tutorial.

    Prerequisites

    The service provider can load the WSDL description of the e-mail Web service. The Web service describedfunctions correctly.

    Importing a New Adaptive Web Service Model in a Component

    To create a model that is based on a certain Web service, you first require the URL address through whichthe corresponding WSDL description can be accessed. If the address is known, you can then easily createan appropriate Web Dynpro model easily.

    1. In the project structure, expand the node Web Dynpro Web Dynpro Components

    EmailAdWSComp.2. From the context menu, choose Open Data Modelerto start the Data Modeler. Alternatively, you can

    double-click the node.

    3. In the Data Modeler toolbar, choose the Create a model icon.

    4. Place the cursor on the Used Models area and left-click.

    5. The appropriate wizard appears. Choose the Import Adaptive Web Service Model option, followed byNext.

    6. Enter the name EmailAdWSModel com.sap.tc.wd.adws.model.emailas the model name andas the package name.

  • 7/29/2019 Creating Email Client

    8/25

    Creating an E-Mail Client Using Web Dynpro's Adaptive Web Service Model

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

    2006 SAP AG 8

    7. Under , choose the radio button UDDI or URL, followed by Next.Select WSDL Source

    8. Do not define logical destinations in the next step.

    9. Enter the following WSDL description for the e-mail Web service in the Wsdl field:http://www.abysal.com/soap/AbysalEmail.wsdl

    10. The next wizard page lets you rename namespaces and model class names. After having selected anamespace in the upper table you could select fields in column Editable Model Class Name of thetable below to replace the a given model class names with custom model class names.

  • 7/29/2019 Creating Email Client

    9/25

    Creating an E-Mail Client Using Web Dynpro's Adaptive Web Service Model

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

    2006 SAP AG 9

    Choose Next, as the given model class names are not changed in this sample application.

    The corresponding Adaptive Web Service model classes are then generated by the importer, which displaysa detailed description of the successfully finished model import.

    Note

    Bear in mind that importing a new Web Dynpro model takes place in the first instance on project level andindependent from the components contained therein. If a model is to be used in a component, you have todefine a corresponding model usage. This usage-relation is automatically defined by the data modeler whencarrying out the procedure mentioned above.

    Result

    After the Web Service model has been imported, the corresponding entries are inserted under theEmailAdWSModel node in the Web Dynpro Explorer.

  • 7/29/2019 Creating Email Client

    10/25

    Creating an E-Mail Client Using Web Dynpro's Adaptive Web Service Model

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

    2006 SAP AG 10

    The nodes contained in the EmailAdWSModel represent the Model Classes ( , executable model classes

    ) and their relations ( ) that are visible to you as the application developer. You can subsequently bindthe appropriate context elements to these classes and relations (Context-to-Model binding) to transfer modeldata between context and model.

    Defining Mapping and Binding Relations

    Each Web Dynpro component is supplied with a corresponding ComponentController. This controller is

    responsible for retrieving the data required by the E-mail Web service to send the e-mail. Accordingly, it mustbe able to map the corresponding input and output structures of the e-mail model. To do this, you need tobind the context of the component controller with the created Web service model. You can declare thiscontext-to-model binding between the controller context and the model with the Data Modeler, available asone of the Web Dynpro tools.

    The structure of the Web Dynpro component EmailAdWSComp looks like this in the Data Modeler:

    Binding the Component Controller Context to the Adaptive Web Service Model

    In the Data Modeler, you can easily declare the connection between the context of the component controllerand the Web service model you have created.

    1. In the project structure, expand the node Web Dynpro Web Dynpro Components EmailAdWSComp.

    2. In the context menu, choose the item Open Data Modeler.

    3. In the left toolbar, choose the icon Create a data link.4. Begin above the rectangle Component Controller and left-click. Do this without releasing the mouse

    button.

    5. Draw a line to the EmailAdWSModel rectangle and release the primary mouse button. The ModelBinding Wizard starts automatically.

  • 7/29/2019 Creating Email Client

    11/25

    Creating an E-Mail Client Using Web Dynpro's Adaptive Web Service Model

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

    2006 SAP AG 11

    6. Drag the node of the model class Request _SendEmai l in the EmailAdWSModel to the root node ofthe component controller context, and drop it.

    7. In the subsequent dialog, select the context attributes ReturnCode of the inner context model nodeSendEmailResponse and the attributes FromAddress, MsgBody, Subject and ToAddress of the inner

    model node .SendEmail

    8. In the dialog box that appears next, the declared context-to-model bindings between the context model

    nodes and the related model classes in the EmailAdWSModel are shown graphically:

  • 7/29/2019 Creating Email Client

    12/25

    Creating an E-Mail Client Using Web Dynpro's Adaptive Web Service Model

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

    2006 SAP AG 12

    9. Close the Model Binding Wizard by choosing Finish.

    10. After completion of the model binding, the context structure of the component controller looks asfollows:

    ResultStarting with the model definition, you have now defined a structure of context model elements (model nodesand model attributes) in the component controllerEmai l AdWSComp, and then linked it to the correspondingmodel classes.

    Mapping View Context Elements to Component Context Elements

    In the last section, a structure for context model elements was created in the context of the componentcontroller. This structure is bound to generated model classes. These model classes contain the datarequired for sending the e-mail as well as the return data belonging to the response of the Web service.

    To be able to access this context structure even outside of a view context, the concept ofContextMapping isnow applied. You will learn how to map context elements of a view onto the appropriate context elements ofthe component controller. The context elements of the view context reference merely to the context

    elements defined in the component controller, which themselves in turn reference to the actual business datain the model (more detailed: to the ).model-objects

    Defining a Context Mapping in the Data Modeler

    The Web Dynpro tools enable you to map a context node defined in the context of the view EmailFormViewto a node in the context of the component controller. The context elements still missing in the node of theview context are automatically added and mapped to their respective match in the component context. Inaddition, the Controller Usage of the component controller needed for the context mapping is declared in theview controller.

    To declare the context mapping between the view controller and the component controller you again use theData Modeler.

    1. Open the Data Modelerfor the Web Dynpro component EmailWSComp.

    2. In the left toolbar, choose the icon Create a data link.

    3. Begin above the rectangle EmailFormView and left-click. Do this without releasing the mouse button.

    4. Draw a line to the Component Controllerrectangle and release the left mouse button.

    5. Drag the model node Request_SendEmail in the context of the component controller to the root nodeof the view controller context, and drop it.

    6. In the dialog box that appears, expand the context structure at the left and mark the check boxes of thetwo context elements Request_SendEmail Response SendEmailResponse ReturnCode and

    , then chooseSendEmail Ok.

  • 7/29/2019 Creating Email Client

    13/25

    Creating an E-Mail Client Using Web Dynpro's Adaptive Web Service Model

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

    2006 SAP AG 13

    Note

    The context elements mapped onto one another do not have to have the same name. At the right side of the

    context mapping dialog window you can rename mapped context elements.7. In the final dialog box, the context mapping declared between view and the component controller

    context is displayed graphically:

    Result

    You have created the necessary view context and mapped it to the component context you created

    previously.

  • 7/29/2019 Creating Email Client

    14/25

    Creating an E-Mail Client Using Web Dynpro's Adaptive Web Service Model

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

    2006 SAP AG 14

    You are now in a position to bind UI controls such as input fields to the corresponding context elements.

    Creating the SendEmail Act ion

    To trigger sending the e-mail message from the EmailFormView view using the Web service, you need anassociatedAction. Events belonging to UI elements on the client side such as the onAction event of abutton can then be bound to this action. If a corresponding event handler is assigned to this action, you canreact to the triggering event (clicking a button) of this action in the user interface. You do this byimplementing this event handler in the view controller. In this way, actions represent a link between eventson the client side and event handlers on the server side.

    view.1. Open the View Designer for the EmailFormView

    2. Choose theActions tab.

    3. Choose the New pushbutton to start the dialog box for defining a new action.

    4. Enter the name SendEmail for the new action.

    5. EnterSend Email in the Text field, then choose Finish.

    At runtime, the Text field entry is automatically displayed in the field Text on the button (UI element) after its

    onAction event is bound to the SendEmail action.

    After you have defined the new action named , a corresponding event handler namedSendEmailonAct i onSendEmai l ( ) is automatically created in the view controller class Emai l FormVi ew. j ava. Theactions defined for a view are listed in the View Designer on theActions tab.

    6. Then switch to the Implementation tab. In this way, the Java classes belonging to the view controllerare regenerated. The User Coding Areas that are accessible to you as the application developer areactually implemented in the classEmai l For m. j ava, which has now been extended to include theevent handleronActionSendEmail().

  • 7/29/2019 Creating Email Client

    15/25

    Creating an E-Mail Client Using Web Dynpro's Adaptive Web Service Model

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

    2006 SAP AG 15

    Result

    In this step, you created the SendEmail action for the EmailFormView view. You can now bind a button UIelements onActionevent to this action, which you will do in the next step. At runtime, the onActionSendEMailevent handler is then called after you have clicked the button for sending the e-mail message in the viewcontroller.

    Designing the View Layout

    In this step, you will design the user interface that is used for input and for sending the e-mail message. Youenhance the view layout of the EmailFormView view to include the relevant user interface elements, such aslabels and input fields. Then you perform the data binding between the UI element properties and the contextmodel attributes. Finally, you bind the button event onAction to the SendEmail action for sending the e-mail.It is much easier to add an e-mail input form if you use the Form-Template-Wizard.

    Creating a layout for the EmailFormView view

    The following describes how to design the layout of the EmailFormView view in the View Designer of theWeb Dynpro tools. Afterwards, the view will look like this:

  • 7/29/2019 Creating Email Client

    16/25

    Creating an E-Mail Client Using Web Dynpro's Adaptive Web Service Model

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

    2006 SAP AG 16

    1. Open the EmailFormView view in the ViewDesigner by clicking the Layout tab.

    2. The ViewDesigner displays a existing default text. Simultaneously, the Outline viewdisplays a list ofthe UI elements included. If you select an element in the Outline view or on the Layout tab, itsassociated element properties are shown in the Properties view.

    3. First, adapt the individual properties of the two existing UI elements:

    Property Value

    For the root element RootUIElementContainer

    Properties of TransparentContainer layout

    GridLayout

    For the TextView element named DefaultTextView

    Properties of TextView design header1

    Properties of TextView text Web Dynpro Email Web Service

    LayoutData hAlign center

    LayoutData paddingBottom large

    4. Add a Group UI element named EmailFormGroup. To do this, go to the context menu and choose

    the entry InsertChild above the root element RootUI El ement Cont ai ner of the Outline. Make thefollowing settings:

    Property Value

    For the Group UI element EmailFormGroup

    Properties of Group defaultButtonId SendButton

    Properties of Group design sapcolor

    Properties of Group layout MatrixLayout

    Properties of Group scrollingMode none

    Properties of Group width 70%

    LayoutData hAlign center

    For the Caption UI element EmailFormGroup_Header

    Properties of Caption text Mail

    With the property defaultButtonId you relate the Group UI element with a so-called default button. The action,to which this default button is bound, is automatically triggered by the Web Dynpro client as soon as the userpresses the Return key inside a focused InputField UI element (contained in the Group UI element).

  • 7/29/2019 Creating Email Client

    17/25

    Creating an E-Mail Client Using Web Dynpro's Adaptive Web Service Model

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

    2006 SAP AG 17

    The e-mail input form consists of several pairs ofLabel and InputField UI elements as well as a button forsending the e-mail message. This form can be added easily by using the Form-Template-Wizard for WebDynpro tools in the view layout.

    5. In the view layout, select the UI element EmailFormGroup and then choose the entryApply Templatein the context menu.

    6. Choose the Form icon in the dialog box and then choose Next.

    7. Select the inner context node SendEmail, as well as all context attributes contained in this node. The

    checkboxes Response and ReturnCode must not be checked:

    8. In the next step, change the order of the user interface elements (using the arrow keys) to

    FromAddress, ToAddress, Subject and MsgBody.9. Select the editorTextEdit for the attribute MsgBody and then press Finish.

    10. After that, change the text property for the individual Label-UI-elements to From, To, Subject andMessage.

    11. Select the UI element MsgBody_label and set its property LayoutData vAlign to the value top.

    12. In the Group UI element EmailFormGroup, add an invisible UI element and a Button UI element withID SendButton und and carry out the stated settings. This button is the default button of the Group UIelement EmailFormGroup. To display message texts within the Group UI element we finally add aMessageArea UI element.

    Property Value

    UI element InvisibleElement of type InvisibleUIElement

    Properties of InvisibleElem. layoutdata MatrixHeadData

    Button of typeSendButton Button

    SendButtonProperties of Button id

    Send EmailProperties of Button Tooltip

    Properties of Button layoutdata MatrixData

    UI element MessageArea of type MessageArea

    Properties of MessageArea layoutdata MatrixHeadData

    2LayoutData of MessageArea colSpan

  • 7/29/2019 Creating Email Client

    18/25

    Creating an E-Mail Client Using Web Dynpro's Adaptive Web Service Model

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

    2006 SAP AG 18

    Data Binding to the View Context

    Data binding between the UI elements in the email form and the corresponding context elements wasalready defined automatically during the previous step in the Form Template Wizard.

    Binding Action to onAction Event of the UI Element SendButton

    So that the e-mail message (entered on the client side) can be sent to the Web service (on the server side)using the view controller, a server round trip must be triggered by the SendEmailaction. To do this, you bind

    theonActionevent of the Button UI element .to the action you have created,SendButton SendEmail

    To do this, define the following action binding:

    Property Value

    For the pushbutton of typeSendButton Button

    Event onAction SendEmail

    You bind the action to a user interface element event using the selection list in the right column in theProperties view.

  • 7/29/2019 Creating Email Client

    19/25

    Creating an E-Mail Client Using Web Dynpro's Adaptive Web Service Model

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

    2006 SAP AG 19

    Implementing the Controller Code

    Note

    This section only comprises a basic description of the controller code implementation. You can separatelyread more advanced technical details on coding-specific aspects in the related SDN articleAdaptive WebService Model Controller Coding Explained. This article also describes some technical details which arespecific for theAdaptive Web Service Model like tracing Web Service invocations and programmatically

    modifying Web Service invocation settings with the I WDWSI nvocat i onModi f i er -API and the ServiceExtension Interfaces of the Web Service Runtime.

    Adding the Implementation for the Web Service Connection

    After you have executed all the declarative development steps, such as model binding, context mapping,data binding, and view layout design, you now turn to the implementation of methods in the view- andcomponent controller.

    Controller of the Component EmailAdWSComp: The component controller implements the access tothe used e-mail Web Service model. The context of the controller contains model nodes and modelattributes, which are bound to the imported Web Service model. Alongside the initialization methodwdDoI ni t ( ) , you implement a public method named sendEmai l ( ) to allow another controller to callthe e-mail Web Service.

    Controller of the EmailFormView view: In the implementation of the view controller, you have toimplement the event handleronAct i onSendEmai l ( ) , which , at pressing the pushbutton to send an e-mail message (Action SendMail), is called and displayed on the user interface.

    Implementing the Method wdDoInit()of the Component Controller

    At runtime, the context model node Request_SendEmail that is bound to the model must initially beassociated to an instance of the appropriate executable model class Request_SendEmail. After that, thismodel object can be used in the public method sendEmai l ( ) to execute the Web Service call.

    1. Select the node Web Dynpro Web Dynpro Components EmailAdWSComp ComponentControllerand then click on the tab page Implementation.

    2. After the generation routines have been run once again, the updated source code of the component

    controller implementation is displayed.3. Now add the following Java code into the User Coding Area provided.

    / ** Hook met hod cal l ed t o i ni t i al i ze cont rol l er . */ / / @@end

    public voidwdDoI ni t ( ) {/ / @@begi n wdDoI ni t ( ) // create a new model instance (1)

    model = new EmailAdWSModel();

    // create model objects (2, 3)

    Request_SendEmail requestMO = new Request_SendEmail(model);

    SendEmail emailMO = new SendEmail(model);

    // associate model objects (4)

    requestMO.setSendEmail(emailMO);

    // bind executable model object to context node (5)

    wdContext.nodeRequest_SendEmail().bind(requestMO);/ / @@end

    }

    . . .

    / / @@begi n ot her s

    / / decl are member var i abl e f or model i nst ance of t ype Emai l AdWSModel private EmailAdWSModel model;

    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/900bbf94-a7a8-2910-e298-a651b4706c1ehttps://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/900bbf94-a7a8-2910-e298-a651b4706c1ehttps://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/900bbf94-a7a8-2910-e298-a651b4706c1ehttps://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/900bbf94-a7a8-2910-e298-a651b4706c1e
  • 7/29/2019 Creating Email Client

    20/25

    Creating an E-Mail Client Using Web Dynpro's Adaptive Web Service Model

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

    2006 SAP AG 20

    / / @@end

    4. To enter the source code, you can avail of the Code Assist functions provided by the SAP NetWeaverDeveloper Studio by selecting the keyboard combination CTRL+SPACE.

    5. You can add the missing i mport statements automatically by choosing Source Organize Importsfrom the context menu or by selecting the keyboard combination STRG+SHIFT+O :

    / / @@begi n i mport simport com. sap. t c. wd. adws. comp. emai l . wdp. I Pr i vateEmai l AdWSComp;import com.sap.tc.wd.adws.model.email.EmailAdWSModel;

    import com.sap.tc.wd.adws.model.email.Request_SendEmail;

    import com.sap.tc.wd.adws.model.email.SendEmail;

    / / @@end

    Important Note

    Contrary to the Adaptive RFC Model or to the former Web Service Model the new Adaptive Web Servicemodel object creation always requires a model instance. The model instance is not created and maintainedby the Adaptive Web Service model itself. When creating new model object instances the model must bealways passed to the constructor.

    Implementing the public method sendEmail()in the Component Controller

    The actual Web Service call for sending the e-mail message is implemented in the public methodsendEmai l ( ) in the component controller. Thus, the communication with the e-mail Web Service in thecomponent controller is encapsulated.

    The connection between the view- and component context was already defined beforehand via the definitionof the context-mapping. Thereby, the view-context points at the context data stored in the component-context. As the component controller is used for context-mapping, its I Publ i c-API (contains publicmethods) is also accessible in the view-controller.

    In the Component Controller define the new public method sendEmai l ( ) .

    1. In the Component Controller switch to the Methods tab page.

    2. Choose New to add a new public controller method.

    3. In the first dialog step, select method type Method.

    4. Enter the name sendEmail for the method, thereby keeping the type of the return value, void.

    5. Close this declaration step by choosing Finish.

    6. Use the Implementation tab page to implement the newly defined method.

    7. In the public method sendEmai l ( ) , add the following source code: You find more detailedbackground information about the methods execut e( ) and i nval i dat e( ) in the tutorial appendix .

    / / @@begi n j avadoc: sendEmai l ( ) / ** Decl ared met hod. */ / / @@end

    public voidsendEmai l ( ) {

    / / @@begi n sendEmai l ( ) IWDMessageManager msgMgr = wdComponentAPI.getMessageManager();

    Request_SendEmail requestMO =

    wdContext.currentRequest_SendEmailElement().modelObject();

    requestMO.wdSetInvocationLogEnabled(

    logger.beDebug() ? true : false);

    try {

    // call Email Web Service and update dependent

    // model node 'Response'

  • 7/29/2019 Creating Email Client

    21/25

    Creating an E-Mail Client Using Web Dynpro's Adaptive Web Service Model

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

    2006 SAP AG 21

    wdContext.currentRequest_SendEmailElement()

    .modelObject().execute();

    wdContext.nodeResponse().invalidate();

    BigDecimal returnCode =

    wdContext.currentSendEmailResponseElement().getReturnCode();

    String msg =

    "Email Web Service returned " + returnCode.toString();

    if (returnCode.intValue() == 0) {msgMgr.reportSuccess("Your email was successfully sent ("

    + msg + ")!");

    } else {

    msgMgr.reportWarning(

    "Your email was not successfully sent (" + msg + ")!");

    }

    } catch (CMIException ex) {

    msgMgr.reportException(ex.getLocalizedMessage(), true);

    this.logWSInvocation(requestMO, ex);}

    / / @@end}

    Notes

    To use the generic UI service provided by the interface I WDMessageManager for displaying message textsin the user interface, you must insert an appropriate import line in the controller implementation. To do this,choose the entry Source Organize Imports from the context menu of the source code editor(Implementation tab).

    For the sake of simplicity we do not define translatable message texts in the components message poolhere but directly pass hard-code message strings to the message manager. In an internationalized WebDynpro application translatable texts and messages must be defined in the message pool first; afterwardsyou can access them as constants of the generated interface I Message.

    After the i mport statements have been adjusted, the I WDMessageManager interface is imported into the

    component controller.

    / / @@begi n i mport s...import com.sap.tc.webdynpro.progmodel.api.IWDMessageManager;

    / / @@end

    Implementing the Action Event HandleronActionSendEmail()

    After you implemented the component controller, you only have to call the public method sendEmai l ( ) ofthe component controller in the action event handleronAct i onSendEmai l ( ) of the view controller totrigger the e-mail Web Service call.

    8. After selecting the node Web Dynpro Web Dynpro Components EmailAdWSComp Views

    EmailFormView, change to the tab page Implementation to display the implementation of the viewcontroller.

    9. In the onAct i onSendEmai l ( ) method, enter the following source code:

    public voidonAct i onSendMai l (com. sap. t c. webdynpro. progmodel . api . I WDCust omEvent wdEvent ) {/ / @@begi n onAct i onSendMai l ( ServerEvent ) wdThis.wdGetEmailAdWSCompController().sendEmail();

    / / @@end}

  • 7/29/2019 Creating Email Client

    22/25

    Creating an E-Mail Client Using Web Dynpro's Adaptive Web Service Model

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

    2006 SAP AG 22

    Result

    The Developer Studio updates and compiles the Java classes belonging to your project. (Note: Compilationonly occurs if you are using the Workbench standard settings.) After you have done this, no more errormessages should appear in your tasks view.

    Build ing, Deploying, and Running the Project

    Now that you have reached this stage, you can start the fully developed example application in the Web

    Browser as described below.However, some preparations are essential before you can deploy and run the application successfully on theSAP J2EE Engine. Go through each of the following prerequisites carefully.

    Prerequisites

    The external e-mail Web service used in the example application is available. You have made sure thatthe SAP J2EE Engine has been launched and that you are connected to an appropriate databaseinstance of the SAP DB. To do this, referto Starting and Stopping the SAP J2EE Engine [extern]

    You have checked that the configuration settings for the J2EE server are entered correctly in theDeveloper Studio. To check the server settings, choose the menu path WindowPreferencesSAPJ2EE Engine.

    Building the Project

    1. Save the current status of the metadata for the project using the button in the upper applicationtoolbar of your Developer Studio, if you have not already done so.

    2. Open the context menu for the project node (TutWD_EmailAdWS) in the Web Dynpro Explorer and

    choose Rebuild Project. Make sure that the Tasks view does not display any errors for your project.You can ignore any warning messages forlabelForproperties that have not been set.

    Deploying and Launching the Application...

    3. In the Web Dynpro Explorer, open the context menu for the application object EmailAdWSApp.

    4. Choose Deploy new archive and run.

    ResultThe Developer Studio performs the deployment process in one single step, based on an automaticallygenerated Enterprise Archive File, and then automatically launches your application in the Web Browser.

  • 7/29/2019 Creating Email Client

    23/25

    Creating an E-Mail Client Using Web Dynpro's Adaptive Web Service Model

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

    2006 SAP AG 23

    Test your new Web Dynpro application by entering your own e-mail data in the input fields From, To,Subject, and Message, and then click on Send.

    After you have triggered a server roundtrip (here you communicate with the E-mail Web service), a successmessage is displayed on the user interface in the Web Browser if no errors have occurred during sending.The result value returned by the e-mail Web service is also displayed in the message text.

  • 7/29/2019 Creating Email Client

    24/25

    Creating an E-Mail Client Using Web Dynpro's Adaptive Web Service Model

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

    2006 SAP AG 24

    Related Content

    SDN Article:Adaptive Web Service Model Controller Coding Explained SDN Article: Using the Adaptive Web Service Model SDN Wiki: FAQ - Models - Adaptive Web Service

    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/900bbf94-a7a8-2910-e298-a651b4706c1ehttps://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/b2bc0932-0d01-0010-6d8e-cff1b2f22bc7https://wiki.sdn.sap.com/wiki/display/WDJava/FAQ+-+Models+-+Adaptive+Web+Servicehttps://wiki.sdn.sap.com/wiki/display/WDJava/FAQ+-+Models+-+Adaptive+Web+Servicehttps://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/b2bc0932-0d01-0010-6d8e-cff1b2f22bc7https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/900bbf94-a7a8-2910-e298-a651b4706c1e
  • 7/29/2019 Creating Email Client

    25/25

    Creating an E-Mail Client Using Web Dynpro's Adaptive Web Service Model

    Copyright

    Copyright 2006 SAP AG. All rights reserved.

    No part of this publication may be reproduced or transmitted in any form or for any purpose without theexpress permission of SAP AG. The information contained herein may be changed without prior notice.

    Some software products marketed by SAP AG and its distributors contain proprietary software componentsof other software vendors.

    Microsoft, Windows, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation.

    IBM, DB2, DB2 Universal Database, OS/2, Parallel Sysplex, MVS/ESA, AIX, S/390, AS/400, OS/390,OS/400, iSeries, pSeries, xSeries, zSeries, z/OS, AFP, Intelligent Miner, WebSphere, Netfinity, Tivoli,Informix, i5/OS, POWER, POWER5, OpenPower and PowerPC are trademarks or registered trademarks ofIBM Corporation.

    Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks ofAdobe Systems Incorporated in the United States and/or other countries.

    Oracle is a registered trademark of Oracle Corporation.

    UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group.

    Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or

    registered trademarks of Citrix Systems, Inc.HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C, World Wide WebConsortium, Massachusetts Institute of Technology.

    Java is a registered trademark of Sun Microsystems, Inc.

    JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology inventedand implemented by Netscape.

    MaxDB is a trademark of MySQL AB, Sweden.

    SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, and other SAP products and servicesmentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG inGermany and in several other countries all over the world. All other product and service names mentionedare the trademarks of their respective companies. Data contained in this document serves informationalpurposes only. National product specifications may vary.

    These materials are subject to change without notice. These materials are provided by SAP AG and itsaffiliated companies ("SAP Group") for informational purposes only, without representation or warranty of anykind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The onlywarranties for SAP Group products and services are those that are set forth in the express warrantystatements accompanying such products and services, if any. Nothing herein should be construed asconstituting an additional warranty.

    These materials are provided as is without a warranty of any kind, either express or implied, including butnot limited to, the implied warranties of merchantability, fitness for a particular purpose, or non-infringement.

    SAP shall not be liable for damages of any kind including without limitation direct, special, indirect, orconsequential damages that may result from the use of these materials.

    SAP does not warrant the accuracy or completeness of the information, text, graphics, links or other items

    contained within these materials. SAP has no control over the information that you may access through theuse of hot links contained in these materials and does not endorse your use of third party web pages norprovide any warranty whatsoever relating to third party web pages.

    Any software coding and/or code lines/strings (Code) included in this documentation are only examples andare not intended to be used in a productive system environment. The Code is only intended better explainand visualize the syntax and phrasing rules of certain coding. SAP does not warrant the correctness andcompleteness of the Code given herein, and SAP shall not be liable for errors or damages caused by theusage of the Code, except if such damages were caused by SAP intentionally or grossly negligent.