+ All Categories
Home > Documents > How to GuideforCAF

How to GuideforCAF

Date post: 02-Jun-2018
Category:
Upload: will-sun
View: 223 times
Download: 0 times
Share this document with a friend

of 67

Transcript
  • 8/10/2019 How to GuideforCAF

    1/67

    Composite Toolbox

    NPI Demo & Innovation Team

    2006

    How-to-Guide

    CAF CoreVersion 2.0

  • 8/10/2019 How to GuideforCAF

    2/67

    TABLE OF CONTENTS

    1 Overview ......................................................................................................................................... 1

    1.1. Story Outline................................................................................................................................. 1

    1.2. Roles............................................................................................................................................. 1

    1.3. Users ............................................................................................................................................ 1

    1.4. Duration ........................................................................................................................................ 1

    2 Detailed Description....................................................................................................................... 3

    2.1. Example of a CAF Core Application............................................................................................. 3

    2.1.1 Architecture of the application................................................................................................... 4

    2.2. Building the CAF Core Application ............................................................................................... 6

    2.2.1 Building a CAF Core Application ........................................................................................... 6

    2.2.2 Defining the entities, their attributes and operations............................................................. 9

    2.2.3 Define the application services the business logic........................................................... 15

    2.3. The Web Dynpro Model.............................................................................................................. 27

    2.3.1 Generate the Web Dynpro Model........................................................................................ 27

    2.3.2 Create the Web Dynpro application .................................................................................... 28

    2.3.3 Create the context values in the Web Dynpro view component ......................................... 31

    2.3.4 Create the UI elements in the Web Dynpro view component ............................................. 35

    2.3.5 Coding in the Web Dynpro view component....................................................................... 38

    2.3.6 Building, deploying and running the application.................................................................. 44

    2.4. Extending the application with Enterprise Services.................................................................... 46

    2.4.1 Integrating an Enterprise Service (importing a Web Service)............................................. 46

    2.4.2 Defining the entities, their attributes and operations........................................................... 47

    2.4.3 Map the operations to external services ............................................................................. 50

    2.4.4 Define the relationship to the employee.............................................................................. 53

    2.4.5 Define the application services the business logic........................................................... 53

    2.4.6 Configuring the external service.......................................................................................... 58

    2.5. Changing the Web Dynpro Model .............................................................................................. 59

    2.5.1 Generate the Web Dynpro model........................................................................................ 59

    2.5.2 Change the Web Dynpro application .................................................................................. 60

    2.5.3 Change the context values in the Web Dynpro view component........................................ 61

    2.5.4 Change the UI elements in the Web Dynpro view component ........................................... 622.5.5 Building, deploying and running the application.................................................................. 63

  • 8/10/2019 How to GuideforCAF

    3/67

    1

    1 OVERVIEW

    1.1. STORY OUTLINE

    This document explains how to create composite application with own persistency and business logic

    the Composite Application Framework Core.It starts with modeling the entities and the application service in CAF Core and continues with WebDynpro. Here it is shown how the generated Web Dynpro models from CAF core are connected to aWeb Dynpro application.

    This application is used as a step in the FirstDay scenario and was created as an iView/Page CallableObject (not as a Web Dynpro Callable Object). Refer to the document HowTo_CAF_GP for moredetailed information on Guided Procedures. Also refer to the storyboard Demonstrating_CAF for ademo of how to integrate CAF Core with Visual Composer and Guided Procedures.

    This documentation assumes you will be working directly on the operating system all references tothe Web Application Server therefore refer to localhost.

    1.2. ROLES

    DESIGNATION NAME COMMENTS

    End user Miller, Jamie The application may be usedas part of the FirstDay GuidedProcedure.

    1.3. USERS

    Predefined users Password Comments

    CTB_ADMIN sap123 Administrator for WebAS and EnterprisePortal used for design time anddevelopment purposes

    sapides123 SDM deployment from the IDE

    14132 sap123 User (Jamie Miller) for differentscenarios

    admin admin Administrator for ERP. Used to grantaccess to the backend.

    Alternatively, CTB_ADMIN/sap123 willalso work.

    1.4. DURATION

    DESCRIPTION

    2.2: Offline CAF Core 90 min (standalone CAF application with local persistency)

  • 8/10/2019 How to GuideforCAF

    4/67

    2

    2.4: Online CAF Core 90 min (CAF application with Enterprise Service integration)

  • 8/10/2019 How to GuideforCAF

    5/67

    3

    2 DETAILED DESCRIPTION

    2.1. EXAMPLE OF A CAF CORE APPLICATION

    In this first section you will see the result of a CAF Core application using Web Dynpro as UI.

    Start the application from the Enterprise Portal

    Log onto the Enterprise Portal as anadminstrator

    (CTB_ADMIN http://localhost:51000/irj).

    You can start the application directly from theportal with the link CAF Core in the worksetCompositeToolbox / Work Area

    With this application, a user can register ownequipment (hardware, phones etc) withoutaccessing external system. The applicationhas its own persistency and administratesthe objects itself. (The business case istargeting quick-win and enhancements of

    existing systems typically not supporting therequired functionality).

    The application retrieves the user-informationfrom the portal and uses these to build anobject model with a reference to sub-entitiesequipments.

    Notice: This application can be accessed inthe same way as any other application in theGuided Procedures Design Time whendesigning callable objects.

  • 8/10/2019 How to GuideforCAF

    6/67

    4

    Notice: The application can also be accessedas any other Web Dynpro applications fromthe Web Dynpro Administration page.

    To do this, please navigate to:

    http://localhost:51000/webdynpro/dispatcher/sap.com/tc~wd~tools/Explorer

    1. Expand to the folder sap.com.

    2. Open the foldersap.com/master~core~register~webdynpro

    3. Open the application RegisterApp andrun it from the detail view.

    2.1.1 ARCHITECTURE OF THE APPLICATION

    From the picture to the right, you cansee that all entity modeling and thepersistency is taken care of by theCAF Core framework. Theapplication service RegisterAppencapsulates the access to the entityEmployee, which has a zero-to-many relationship with theEquipments. This application

    service is then encapsulated as aWeb Service and may be used in anyother application. It is also possible touse it as a Web Dynpro modeldirectly, which is a much fasterapproach if you use it asDevelopment Components as in thisdocument.

  • 8/10/2019 How to GuideforCAF

    7/67

    5

    The process flow goes as follows:

    1. The Web Dynpro applicationtriggers a call to the CAF Core byusing the serviceFindEmployeeByPersonalID

    2. The CAF Core application

    service uses the entity serviceoperation FindByPersonalID toaccess the entity

    3. The framework thenautomatically triggers a read-operation to the local databasefor the entity Employee

    4. and since this entity has arelationship defined, it does thesame with Equipment

    Later in this document, the

    application is enhanced by an accessto an external system a HR system.The architecture for this applicationlooks like this:

    The according process flow goes asfollows:

    Step 1-4 are similar to the flow above

    5. The operationFindByEmployeenr is executedon the remote entityOrganization. Now, this connectsto the backend system and getsa employeenr back. Thisforeign/remote key is stored as areference in the localdatabase(!)

    6. and automatically used by theRead operation to access thebackend. This is the earliest pointwhere the data can be mappedto the entity in order to be able touse them in e.g. a Web Dynprocontext.

  • 8/10/2019 How to GuideforCAF

    8/67

    6

    2.2. BUILDING THE CAF CORE APPLICATION

    This section covers the steps necessary to build a CAF Core application on your own. It demonstrateshow to create data objects with complex attributes (entity services), the relations between them andthe business logic (application services). Further you will see how the life-cycle methods (create-read-update-delete) of the entities are generated and how these are used by the business logic.

    CAF Core applications target the consumption of services and custom defined business logic with aown persistency, but does not cover UI. Therefore, this document also describes how the applicationcan be exposed using the Web Dynpro UI.

    2.2.1 Building a CAF Core Application

    In the SAP NetWeaver Developer Studio,

    open the perspective CompositeApplication Services.

    Notice: Due to limitations of the file-lengthof generated code (especially for WebDynpro), the Development ConfigurationRoot has to be chosen carefully. This rootis where all local components, referencesand metadata are located and from wherethe code will be generated. The root foldershould be as close to the file-system rootas possible (do not use c:\documentsand settings\user). The settings are

    optimized for this installation and can befound in Developer Studio underPreferences/Java DevelopmentInfrastructure/Development ConfigurationPool. Do not change these settings!

    The CAF Core application will be aDevelopment Component. Create a newproject from the menu File New Project.

  • 8/10/2019 How to GuideforCAF

    9/67

    7

    Select the type DevelopmentComponent Project and continue withNext

    For this scenario, there is no need to use

    the NWDI tracks, so the application canbe developed with local references. SelectMyComponents from the node LocalDevelopment.

    Continue with Next

    Notice: The official way of implementingthese applications would be to takeadvantage of the NWDI concept andcreate the application as a developmentcomponent (DC) within a softwarecomponent (SC) defined in the DesignTime Repository (DTR). In particular if you

    would like to reference other DCs (e.g. theGuided Procedure API), there is no wayaround defining a SC with all necessaryreferences and create your DC in thistrack. Please refer to the chapter BuildingCallable Objects in the document GuidedProcedures for more details.

  • 8/10/2019 How to GuideforCAF

    10/67

    8

    Call your applicationdemo/core/register. Enter a text for theCaption (e.g. demo/core/register) andcontinue with Next

    Notice: The applicationmaster/core/register is already availablein the Developer Studio and is usedthroughout the runtime examples.

    Confirm the next screen with Next.Theproject is ready to be generated.

  • 8/10/2019 How to GuideforCAF

    11/67

    9

    A CAF Core project is in fact acompilation of 6 sub-projects:

    - Enterprise Application: Container project

    - Dictionary: Data-types

    - EJB-Module: Persistency and access

    - Metadata: Definition of entities etc

    - Web Dynpro: Model generation

    - UME: Permission definition for entities

    When clicking on Finish, all project codewill automatically be generated.

    2.2.2 Defining the entities, their attributes and operations

    The focus of the application is on theentities and the corresponding life-cyclemethods. In this matter, the features tocover are:

    - Entity Employee

    - Entity Equipment with a reference toEmployee

    - Application service for maintaining theentities (create, delete, update, searchetc)

    Navigate to the node Entity Services.From the context-menu, select New.

    The first entity should be calledEquipment.

    Confirm with Finish.

  • 8/10/2019 How to GuideforCAF

    12/67

    10

    Before you start defining the attributesand operations, switch off the Permissionchecks.

    Navigate to the tab page Permissionsand uncheck the optionPermission

    checks enabled

    Notice: With the permission checkenabled, an administrator could setindividual permissions on the entityhierarchies within the application. E.g.some users may have access to all levelof an employee like salary payments,whereas other are only allowed access tothe top-level of the employee.

    In this scenario, the entity Equipmentdescribes the hardware assets anemployee might have. These areidentified by an attribute equipmentIDand an attribute description.

    To add the attributes, navigate to the tabpage Attributes. On the entityEquipment, select Create Attributefrom the context-menu.

    Add the name equipmentID.Select the Datatypecom.sap.caf.core.shortText from thedictionary (click on Browse to open).

    Confirm with Finish

  • 8/10/2019 How to GuideforCAF

    13/67

    11

    Create the attribute description in thesame way:

    Name description

    Datatype com.sap.caf.core.shortText

    Confirm with Finish

    The first entity is now ready.

    Now, create the next entity.

    Navigate to the node Entity Servicesand from the context-menu, select New.

    The second entity should be calledEmployee.

    Confirm with Finish.

    First, uncheckthe permission check.

  • 8/10/2019 How to GuideforCAF

    14/67

  • 8/10/2019 How to GuideforCAF

    15/67

    13

    A reference has been added. Change thename of the reference to equipments.

    (Open the tab page Properties on thelower view and change the value of theproperty Name)

    Since a employee can have more thanone equipment registered, the cardinalityof the relation has to be changed from0..1 to 0..n.

    (Open the tab page Properties on thelower view and change the value of theproperty Cardinality)

    The attribute modeling is now finished.When the project is build, tables metadefinitions will be created. Thesedefinitions are used for creating therequired tables and the referencesbetween them on the server where theapplication is deployed. Notice forinstance the property DB Field in thescreenshot. The field PRIMARYKEY willbe created at deployment-time. On the tabpage Persistency you will find moreinformation on table names.

  • 8/10/2019 How to GuideforCAF

    16/67

    14

    When defining the entity models, severallife-cycle operations are generatedautomatically. These are operations formaintaining the instances of the entitieslike creating, reading, updating and

    deleting. Also, a generic search operationis generated.

    In addition to these operations whichare used as services later in this section -this application would need a operation forsearching employee by using theirpersonal-ID.

    Navigate to the tab page Operationsand press Add.

    Call the operation findByPersonalID(use the same for the description).

    Select the attribute personalID thiswill be the input parameter for theoperation.

    Confirm with Finish.

    Notice: The term operation is used fordifferentiating the business orienteddefinition of functionality from the more

    technical oriented methods generatedout of the definitions. The methods arefound in the code.

  • 8/10/2019 How to GuideforCAF

    17/67

    15

    The entities are ready for use there hasbeen no line of code and yet thisapplication has a complete objectdefinition, an independent persistencymodel, object-relationships and life-cycle

    operations.

    You could take a look on some of thecode generated out of this modeling bynavigating to the tab pageImplementation. You can not do anychanges to the code, though.

    2.2.3 Define the application services the business logic

    With the application services you definethe business logic you want yourapplication to process. You can makeyour own custom operations or you canintegrate entity-models or externalservices and wrap generic operationsaround these e.g. combine a call to anEnterprise Service with an own entitymodel.

    In this section, you will use the applicationservice as an entry point of the entity

    model.

    To create an application service, navigateto the node Application Services andselect New from the context menu.

  • 8/10/2019 How to GuideforCAF

    18/67

    16

    Call the service RegisterApp

    Confirm with Finish.

    Now, to use the entities you createdearlier a dependency must be defined.

    Navigate to the tab pageDependencies, select the EntityServices Employee and Equipmentand add themto the application serviceby clicking on the button:

    The entities are now ready to be used bythe application services.

    The purpose of this application (consistingof CAF Core and Web Dynpro) is to let an

    employee be able to add new equipmentsto his assets (create) and also removethem e.g. when his notebook is replaced.In addition, the application needs asearch-operation to automatically retrievethe employee-object and thecorresponding equipments when startingup.

  • 8/10/2019 How to GuideforCAF

    19/67

    17

    Some of the operations are executedautomatically through the entity life-cyclemodel; others must be implemented byhand.

    Following functionality is needed by theWeb Dynpro application:

    - search for an employee: Done by theapplication at start-up

    - create a new employee: Done by theapplication, if the employee doesnt existat start-up

    - create a new equipment: Done by theemployee himself when running theapplication

    In addition, two operations will be createdfor retrieving the entity employee andthe equipment. These operations will

    only return the entity itself (theseoperations are used in the demo of VisualComposer refer to the documentdemonstrating CAF)

    - search for an employee: Return onlyentity

    - search for an equipment: Return onlythe equipments (belonging to anemployee)

    Some operations are used indirectly bythe Web Dynpro application:

    - read an employee: Entity operation

    - update an employee: Entity operation

    - delete an employee: Entity operation

    - read an equipment: Entity operation

    - update an equipment: Entity operation

    - delete an equipment: Entity operation

  • 8/10/2019 How to GuideforCAF

    20/67

    18

    To add new operations, navigate to thetab page Operations and press thebutton Add.

    Select the operation type Access andcheck the options Create, Read,Update and Delete.

    Continue with Next.

    Enter Employee as description andselect the data type Employeefromthe catalog.

    Leave the permission check Disabled.

    Confirm with Finish.

  • 8/10/2019 How to GuideforCAF

    21/67

    19

    Currently, you must manually add apredefined exception class to theoperation.

    From the Attributes / Type repository,select ServiceException and add this to

    all 4 operations by pressing the buttonFault.

    The life-cycle operations for theEmployee entity are ready

    Add the next operation this time forcreating the equipment.

    Press Add from the operations view.

    Again, select the operation type Accessand check the options Create, Read,Update and Delete.

    Continue with Next.

    Enter Equipment as description andselect the data type Equipmentfromthe catalog.

    Leave the permission check Disabled.

    Confirm with Finish.

  • 8/10/2019 How to GuideforCAF

    22/67

  • 8/10/2019 How to GuideforCAF

    23/67

    21

    Select the attributepersonalID as inputparameter.

    Confirm with Finish.

    Once again, you must manually add apredefined exception class to theoperation.

    From the Attributes / Type repository,select ServiceException and add this tothe operation by pressing the buttonFault.

    The search operation is now ready.

    Add another operation this time forsearching the employee by his personalID and retrieving only the entity itself.

    Again, press Add from the operationsview.

    Select the operation type Custom.

    Continue with Next.

  • 8/10/2019 How to GuideforCAF

    24/67

    22

    EnterFindEmployeeOnlyByPersonalID asname of the operation (and the same forthe description).

    Continue with Finish.

    The input and output parameters shouldnow be implemented.

    Select the operation and from the catalogSimple Types/com.sap.caf.core, selectshortText and press Input.

    Change the name of the property topersonalID.

    Add the type Employee as parameterfor Output.

  • 8/10/2019 How to GuideforCAF

    25/67

    23

    Finally, add the to exception classesCAFFindException andServiceException (using the buttonFault)

    Add another operation this time forsearching the equipment by his personalID and retrieving only the entity itself.

    Again, press Add from the operationsview.

    Select the operation type Custom.

    Continue with Next.

    EnterFindEquipmentOnlyByPersonalID asname of the operation (and the same for

    the description).

    Continue with Finish.

  • 8/10/2019 How to GuideforCAF

    26/67

    24

    The input and output parameters shouldnow be implemented.

    Select the operation and from the catalogSimple Types/com.sap.caf.core, selectshortText and press Input.

    Change the name of the property to

    personalID.

    Add the type Equipment as parameterfor Output.

    Change the Collection property to list forreturning all equipments (instead of justone)

    Finally, add the to exception classesCAFFindException andServiceException (using the buttonFault)

    You now have eleven customimplemented operations, which all requirea little bit of coding.

    Navigate to the Implementation tabpage.

    In the Outline view, you can see themethods generated out of the threeoperations. The code will be added tothese methods.

    1: Start with the methodcreateEmployee().

    //@custom code start - createEmployee

    retValue = getEmployeeService().create();

  • 8/10/2019 How to GuideforCAF

    27/67

    25

    Click on this method; add the followingcode to the method between the brackets(you will have to replace the coderetValue=null):

    //@custom code end - createEmployee

    2. method

    readEmployee(string), add:

    (you will have to replace the coderetValue=null):

    //@custom code start - readEmployee

    retValue = getEmployeeService().read(key);

    //@custom code end readEmployee

    3. method

    updateEmployee(Employee), add:

    //@custom code start - updateEmployee

    getEmployeeService().update(dS0);

    //@custom code end updateEmployee

    4. method

    deleteEmployee(Employee) , add:

    //@custom code start - deleteEmployee

    getEmployeeService().delete(dS0);

    //@custom code end deleteEmployee

    5. method

    createEquipment, add:

    (you will have to replace the coderetValue=null):

    //@custom code start - createEquipment

    retValue = getEquipmentService().create();

    //@custom code end createEquipment

    6. method

    readEquipment(string), add:

    (you will have to replace the coderetValue=null):

    //@custom code start - readEquipment

    retValue = getEquipmentService().read(key);

    //@custom code end readEquipment

    7. method

    updateEquipment (Equipment), add:

    //@custom code start - updateEquipment

    getEquipmentService().update(dS0);

    //@custom code end updateEquipment

    8. method

    deleteEquipment(Equipment), add:

    //@custom code start - deleteEquipment

    getEquipmentService().delete(dS0);

    //@custom code end deleteEquipment

    9. method

    FindEmployeeByPersonalID() , add:(you will have to replace the coderetValue=null)

    //@custom code start - FindEmployeeByPersonalID

    retValue = getEmployeeService().findByPersonalID(personalID);

    //@custom code end FindEmployeeByPersonalID

    10. method

    FindEmployeeOnlyByPersonalID() ,add:

    //@@custom code start -FindByPersonalIDEmployeeOnly(java.lang.String) retValue =null;

    java.util.List employees =getEmployeeService().findByPersonalID( newcom.sap.caf.rt.bol.util.QueryFilter(personalID));

  • 8/10/2019 How to GuideforCAF

    28/67

    26

    Object[] values = employees.toArray();

    if (values.length > 0) {retValue = (Employee)values[0];

    }

    //@@custom code end -FindByPersonalIDEmployeeOnly(java.lang.String)

    11. method

    FindEquipmentOnlyByPersonalID() ,add:

    //@@custom code start -FindEquipmentOnlyByPersonalID(java.lang.String)

    retValue =null;

    java.util.List employees =getEmployeeService().findByPersonalID( newcom.sap.caf.rt.bol.util.QueryFilter(personalID));

    Object[] values = employees.toArray();

    if (values.length > 0) {Employee employee = (Employee)values[0];

    java.util.List equipmentlist = employee.getEquipments();

    retValue =newjava.util.ArrayList();

    Object[] values2 = equipmentlist.toArray();

    for (intj = 0; j < values2.length; j++) {

    String key = equipmentlist.get(j).toString();Equipment equipment = getEquipmentService().read(key);retValue.add(equipment);

    }}

    //@@custom code end -FindEquipmentOnlyByPersonalID(java.lang.String)

    The coding is now ready. Save allmetadata by pressing the button

    To build the application, select theproject root.

    From the context menu, selectDevelopment Component and selectBuild from this menu.

    Confirm any pop-ups and wait until thecomponent has been build.

  • 8/10/2019 How to GuideforCAF

    29/67

    27

    The application is now ready to bedeployed.

    To do so, select Deploy to J2EEEngine from the context menu and waituntil all 5 sub-projects are finished.

    SDM will ask for a password the first timeit is used please refer to 1.3.

    The successful result is shown to theright.

    Notice: You could also skip thedeployment step, since the component

    will be deployed later in this chapteranyway, but as a preview, you could test itwith the CAF service-browser tool:

    Open the URLhttp://localhost:51000/caf

    Logon as adminstrator (CTB_ADMIN) refer to 1.3 for password.

    Then Test tools

    Go to Service Browser

    Open the application RegisterApp inthe folder demo.core.register and try itout.

    The CAF Core application is ready andcan be used in other applications likeVisual Composer or Web Dynpro. Theusage of CAF Core in Visual Composer isdescribed in the storyboardDemonstrating CAF in particular howto generate Web Services from CAFCore. The rest of this How-To-Guideconcentrates on how to use the CAF Coreapplication in a Web Dynpro.

    2.3. THE WEB DYNPRO MODEL

    2.3.1 Generate the Web Dynpro Model

  • 8/10/2019 How to GuideforCAF

    30/67

    28

    Now that the CAF Core application isfinished, it is time to use the functionalityin a UI.

    You have the option to exposure theapplication services as a Web Service,but in this example, a Web Dynpro model

    will be generated out of the projectinstead and used directly in the WebDynpro project.

    Please refer to the documentDemonstrating_CAF for more details ongenerating Web Services from CAF Coreand use them in Visual Composer.

    Optional: If you would like to create aWeb Service right now, do the following:

    1. Check the option Remote Enabled

    Service on the tab page General ofthe Application Service or EntityService

    2. In the Service Explorer, select theApplication Service and select WebService => New from the contextmenu.

    3. Follow the instructions

    4. The web services can be tested onthe URL:http://localhost:51000/wsnavigator/enterwsdl.html

    In this scenario a Web Dynpro model willbe created from CAF Core and used inthe Web Dynpro project.

    Select the project rootand selectCreate Web Dynpro Model from thecontext menu.

    Notice: You now have a model ready tobe used in projects. The normal way to do

    so is to define the model as a public partof the project and in the consumer-projectadd a reference to this by adding a UsedDC. For simplicity reasons, this conceptwill not be discussed here.

    2.3.2 Create the Web Dynpro application

  • 8/10/2019 How to GuideforCAF

    31/67

    29

    As mentioned earlier, the CAF Coreproject comes with a sub-project WebDynpro. This will be used here to createthe UI-application.

    Switch to the Web Dynpro Perspective

    by clicking on the button:

    You can see that the CAF Core services(demo_core_register) have beengenerated and are available to the WebDynpro component.

    Start with creating a new Web DynproComponent.

    From the context menu of the node WebDynpro Components, select Create WebDynpro Component.

  • 8/10/2019 How to GuideforCAF

    32/67

    30

    Call the component EquipmentRegistryand use the component packagecom.sap.demo.core.register.

    Leave the default values and confirm withFinish.

    Add a reference to the model.

    From the context menu of UsedModels, select Add.

    Select the model demo_core_registerand confirm with OK.

  • 8/10/2019 How to GuideforCAF

    33/67

    31

    The model will now be used as part of thecontext of the component view.

    Select Edit from the context menu of theview EquipmentRegistryView.

    2.3.3 Create the context values in the Web Dynpro view component

    The first thing to do, is defining all localcontext elements for the view.

    Navigate to the tab page Context.

    Then create the following modelnodesand attributes (right-click on nodeContext):

    - Model node: Employee

    - Model attribute: personalid

    Select node Employee and create

    - Model node: Equipment

    - Model attribute: description

    - Model attribute: equipmentid

    You now have a local context which willbe mapped to the model generated fromthe CAF Core application.

    To bind this local model to the CAF coremodel, select Edit Model Binding fromthe context menu of the model nodeEmployee.

  • 8/10/2019 How to GuideforCAF

    34/67

    32

    Select AEmployee fromdemo_core_register

    Continue with Next

    Then, select the attribute personalid

    and confirm with Finish.

    The local employee model is now boundto the CAF Core entity model.

    Now, do the same for the model valueEquipment; From the context menu ofthe model node Equipment, select EditModel Binding.

  • 8/10/2019 How to GuideforCAF

    35/67

    33

    Select equipments(AEquipment) withinthe node AEmployee.

    This is the relationship node betweenEmployee and Equipment.

    Continue with Next

    Select the attributes description andequipmentid and confirm with Finish.

    The local equipment model is now boundto the CAF Core entity model.

  • 8/10/2019 How to GuideforCAF

    36/67

    34

    Now, go back to the context root and addthe following valuenodes and attributes(these are the values used in the viewlater):

    (right-click on node Context):

    - Value node: DeleteEquipment

    - Value attribute: equipmentnr

    - Value node: FindEmployee

    - Value attribute: personalid

    - Value node: NewEquipment

    - Value attribute: description

    - Value attribute: equipmentnr

    And finally a value attribute firstnamefrom the root the Context.

    Important: Please make sure that allthree value nodes have the cardinality1..1. Otherwise, you will not be able toadd or delete new equipments.

    Create the actions in the Web Dynpro view component

    The Web Dynpro view will need toactions; a delete and a save action.

    Open the tab page Actions and pressthe button New.

    Call the action Delete and leave alldefault values.

    Confirm with Finish

  • 8/10/2019 How to GuideforCAF

    37/67

    35

    Add another action Save and confirmwith Finish

    2.3.4 Create the UI elements in the Web Dynpro view component

    Now, the UI elements of the view can bedesigned.

    Open the tab page Layout

    In the outline view, deletethe defaultelement.

    Change the layout of theRootUIElementContainer to GridLayout

    and the width to 300px

    Add a new child (from the context menu,select Insert Child).

  • 8/10/2019 How to GuideforCAF

    38/67

    36

    Select Trayand confirm with Finish.

    Define the properties as appropriate, e.g.the text of the Tray_Header toRegistration and the layout of the trayas GridLayout

    Inside of the tray-element, insert 5 childelements of typeTransparentContainer.

    Change the property Layout toMatrixLayout for all containers exceptfor the last one which has aGridLayout.

    Add two elements TextView to the first

    container.

    The text value of the first element is Dear

    The text value of the second element isthe context attribute firstname.(browse and select from the context).

    Notice: The later implementation willretrieve the user from the portal context

  • 8/10/2019 How to GuideforCAF

    39/67

    37

    and fill the local context with the firstnameof the user.

    Add two elements TextView to thesecondcontainer.

    The text value of the first element isPlease register your equipments. Yourpersonal ID is:

    The text value of the second element isthe context attributeEmployee.personalid. (browse and

    select from the context).

    Add an element Table to the thirdcontainer.

    From the context menu of the Table,select Create Binding to attach themodel to it.

    Select the model attributes descriptionand equipmentid.

    Continue with Finish.

  • 8/10/2019 How to GuideforCAF

    40/67

    38

    Add an element Button to the fourthcontainer.

    Change the text of the button to Delete.

    Assign the action Delete to the event

    onAction.The width should be 80px

    Add the following elements to the fifthcontainer:

    - TextView: text Register equipment

    - TransparentContainer: layoutMatrixLayout

    - To this container, add a Label withthe text Equipment Nr

    - To this container, add an InputFieldand assign the context attributeNewEquipment.equipmentnr tothe value property

    - TransparentContainer: layoutMatrixLayout

    - To this container, add a Label withthe text Description

    - To this container, add an InputField

    and assign the context attributeNewEquipment.description to thevalue property

    - To this container, add a Button withthe text Save and assign the actionSave to the event onAction.

    To optimize the appearance, you couldchange the width of the labels and thebutton to 80pxand the inputfields to150px

    The first TransparentContainer should

    have 50pxwidth, the second 300px.

    2.3.5 Coding in the Web Dynpro view component

  • 8/10/2019 How to GuideforCAF

    41/67

    39

    Before start coding, a reference has to beadded to a Development Component foraccessing the portal context.

    Navigate to folder Used DCs and selectAdd Used DC from the context menu.

    Select the DCcom.sap.security.api.sda from thecompartment SAP-JEE.

    Check the option Design Time, BuildTime and Run Time.

    Select the runtime qualifier weak

    Confirm with Finish.

  • 8/10/2019 How to GuideforCAF

    42/67

    40

    Three methods have to be implemented;The methods for the actions Save andDelete and the initialization method ofthe component.

    In these methods a delegation to the CAFCore application services will

    implemented.Open the tab page Implementation; thecode as now generated out of the metainformation.

    To accelerate the coding generation,please add the following importstatements (between the import-brackets):

    import com.sap.security.api.IUser;import com.sap.tc.webdynpro.services.sal.um.api.IWDClientUser;import com.sap.tc.webdynpro.services.sal.um.api.WDClientUser;import com.sap.demo.core.register.services.demo_core_register.employeeservice.AEmployee;import com.sap.demo.core.register.services.demo_core_register.employeeservice.EmployeeServiceProxy;import com.sap.demo.core.register.services.demo_core_register.equipmentservice.AEquipment;import com.sap.demo.core.register.services.demo_core_register.equipmentservice.EquipmentServiceProxy;import com.sap.demo.core.register.services.demo_core_register.registerapp.RegisterAppProxy;

    The first method - wdDoInit() isexecuted when the component starts up.

    This method should do the following:

    1. Get the user data (first name) fromthe portal context.

    2. Assign the first name to the localcontext value

    3. Search in the CAF Core persistencylayer (entity) if the user/employeealready exists

    4. Create a new employee object in CAFCore, if the user is not found

    Add the code between the brackets:

    //@@begin wdDoInit()

    //Retrieve user data from the UME (in the portal)

  • 8/10/2019 How to GuideforCAF

    43/67

    41

    IWDClientUser wdUser = WDClientUser.getLoggedInClientUser();IUser user = wdUser.getSAPUser();String userID = user.getUniqueName();String firstName = wdUser.getFirstName();

    wdContext.currentContextElement().setFirstname(firstName);

    // Search in the CAF Core persistency for the employeewdContext.nodeEmployee().bind(

    RegisterAppProxy.FindEmployeeByPersonalID(userID));if (wdContext.currentEmployeeElement() ==null){

    // No employee with this userid, therefore create a new oneAEmployee newEmployee = EmployeeServiceProxy.create();newEmployee.setPersonalID(userID);

    // Save the changes back to the CAF Core persistencynewEmployee.getAspect().sendChanges();

    // To retrieve the eventual backend data (HR system), search again to// also include the subsequent find-operations (equipments, organization..)wdContext.nodeEmployee().bind(RegisterAppProxy.FindEmployeeByPersonalID(userID));

    }//@@end

    The second method - onActionDelete() is executed when the user clicks on thedelete-button in the view.

    This method should do the following:

    1. Get the reference to the employeeand the equipment of the local context

    2. Remove the current equipment fromthe employee model

    3. Propagates the changes to the CAFCore model

    //@@begin onActionDelete(ServerEvent)

    if (wdContext.currentEquipmentElement() !=null) {AEquipment equipment =

    wdContext.currentEquipmentElement().modelObject();AEmployee employee =

    wdContext.currentEmployeeElement().modelObject();

    employee.removeEquipments(equipment);employee.getAspect().sendChanges();

    }

    //@@end

  • 8/10/2019 How to GuideforCAF

    44/67

    42

    The third method - onActionSave() isexecuted when the user clicks on thesave-button in the view.

    This method should do the following:

    1. Get the values of the fieldsdescription and equipment nr

    2. Creates a new equipment object inCAF Core through the CAFapplication service createEquipment

    3. Assigns the values to the new object

    4. Assigns the new object to the currentemployee model

    5. Propagates the changes to the CAFCore model

    //@@begin onActionSave(ServerEvent)

    String equipmentNr = wdContext.currentNewEquipmentElement().getEquipmentnr();String description = wdContext.currentNewEquipmentElement().getDescription();

    if (equipmentNr !=null && equipmentNr.length() > 0) {

    // If an equipmentnumber has been entered, a new entity will// be createdAEquipment newEquipment = EquipmentServiceProxy.create();newEquipment.setDescription(description);newEquipment.setEquipmentID(equipmentNr);newEquipment.getAspect().sendChanges();

    // Get the reference of the employee-entityAEmployee employee = wdContext.currentEmployeeElement().modelObject();

    // .. and add the reference to the equipmentobject and update it.employee.addEquipments(newEquipment);employee.getAspect().sendChanges();}

    //@@end

    The final step is to create a applicationwhich wraps the Web DynproDevelopment Component.

    Select Create Application from thecontext menu of the Applicationnode.

  • 8/10/2019 How to GuideforCAF

    45/67

    43

    Call the application RegisterApp andselect the packagecom.sap.demo.core.register

    Continue with Next.

    Select the option Use existingcomponent.

    Continue with Next.

  • 8/10/2019 How to GuideforCAF

    46/67

    44

    Leave the default values theEquipmentRegistryis the correctcomponent.

    Confirm with Finish.

    2.3.6 Building, deploying and running the application

    The Web Dynpro application is now readyto be deployed along with the CAF Coreproject.

    Navigateback to the CompositeApplication Service perspective

    To build the application, select theproject root.

    From the context menu, selectDevelopment Component and selectBuild from this menu.

    Confirm any pop-ups and wait until thecomponent has been build.

    Notice: It is advisable to select allcomponents to build to clean upreferences.

  • 8/10/2019 How to GuideforCAF

    47/67

    45

    The application is now ready to bedeployed.

    To do so, select Deploy to J2EEEngine from the context menu and waituntil all 5 sub-projects are finished.

    The successful result is shown to theright.

    You can run the application directly fromthe Web Dynpro Explorer.

    Select Run from the context menu of theApplication RegisterApp and test it asan anonymous user (guest)

    Notice: You can of course also run it fromthe Web Dynpro Content Administration.

    and the result is:

  • 8/10/2019 How to GuideforCAF

    48/67

    46

    2.4. EXTENDING THE APPLICATION WITH ENTERPRISE SERVICES

    This section covers the steps necessary to extend the CAF Core application with a connection to anEnterprise Service (Web Service). The idea is to take advantage of the content provided by SAPs HR-System to bring more information to the application. The service contains information about theorganization the employee belongs to - this information will be displayed in the Web Dynproapplication.

    2.4.1 Integrating an Enterprise Service (importing a Web Service)

    In the SAP NetWeaver Developer Studio,open the perspective CompositeApplication Services.

    Open your project demo.core.register

    Navigate to the node External Serviceand select Import from the context-menu.

    Select Web Service as type of externalservice.

    Continue with Next

  • 8/10/2019 How to GuideforCAF

    49/67

    47

    Select Local File System or URL asWSDL Source.

    Continue with Next

    Enter the URL:

    http://localhost:51080/sap/bc/soap/wsdl11?services=Z_WS_EMPLOYEE_GETDATA&sap-client=200

    Confirm with Finish (and ignore thewarnings)

    Notice: This web service can be testedfrom the WSNavigator. To do so, open aurl

    http://localhost:51000/wsnavigator/enterwsdl.html

    and paste the url of the wsdl into theinputfield.

    The user for accessing the backend isfound in the chapter 1.3.

    The Web Service proxy has now beengenerated is ready to be used. Theauthentication will be configured later inthis chapter.

    2.4.2 Defining the entities, their attributes and operations

    To model the new idea, you will in thissection:

    - create a new entity Organization

    - map operations from the entity to theenterprise service

    - map a relationship from the employeeentity to the organization

  • 8/10/2019 How to GuideforCAF

    50/67

    48

    - create the application service formaintaining the entity (create, delete,update, search etc).

    Navigate to the node Entity Services.From the context-menu, select New.

    The entity should be calledOrganization.

    Confirm with Finish.

    Before you start defining the attributesand operations, switch off the Permissionchecks.

    Navigate to the tab page Permissionsand uncheck the optionPermission

    checks enabled

    In this scenario, the entity Organizationdescribes the assignment of the employeelike cost center, organizational unit and soon. We use the attribute orgunit in thisexample.

    Also, because this will be connected to aweb service, a remote key has to becreated.

    To add the attributes, navigate to the tabpageAttributes.

    On the entity Organization, selectCreate Attribute from the context-menu.

  • 8/10/2019 How to GuideforCAF

    51/67

  • 8/10/2019 How to GuideforCAF

    52/67

    50

    Press Add and enter the namefindbyemployeenr for the operation(and description).

    Select employeenr as your inputattribute.

    Confirm with Finish

    2.4.3 Map the operations to external services

    To tell CAF that this entity will not bemaintained locally, it must be definedaccordingly.

    Open the tab page Persistency anduncheck the option Local Persistency.

    Now, instead of accessing the local(J2EE) database, the CAF will at runtimelook for corresponding services.

    The operations within this entity shouldnow be mapped to the correspondingenterprise service imported earlier in thischapter.

    Open the tab page Datasource andselect the read operation.

  • 8/10/2019 How to GuideforCAF

    53/67

    51

    Press the button to access theavailable external services and checkmark Z_WS_EMPLOYEE_GETDATA.

    Confirm with OK

    The key of the entity should now bemapped to the input parameter to theexternal service.

    Select employeenr and drag it onto theinput parameter EMPLOYEE_ID.

    The result of the service call should nowbe mapped back to the entity.

    Select ORG_UNIT from the return valueRETURNORG and drag it onto theattribute orgunit of the entity.

  • 8/10/2019 How to GuideforCAF

    54/67

    52

    Now, repeat this for the operationfindbyemployeenr:

    Select the operation findbyemployeenr.

    Press the button (on the right side ofthe screen) to access the availableexternal services and check markZ_WS_EMPLOYEE_GETDATA.

    Confirm with OK

    Select minValue and drag it onto theinput parameter EMPLOYEE_ID.

    Select PERNO from the return valueRETURNORG and drag it onto theattribute employeenr of the entity.

    Notice: This might look a little strange, butthis is what happens in the application atruntime:

    1. The Findby-operation of theorganization entity is called by theapplication service (youll see later).What interests the application at thistime is the employeenr, which is usedby the entity as a foreign key to thebackend-systems database.

    2. This foreignkey is saved locally andlater used automatically by the read-operationwhen the employee entity

    tries to access the organization entity(e.g. when accessed in a Web Dynprocontext).

    3. The read-operationgets theORG_UNITback as result from theweb service and maps this to its ownattributeorgunit.

  • 8/10/2019 How to GuideforCAF

    55/67

    53

    2.4.4 Define the relationship to the employee

    From a logical point-of-view, an employeebelongs to one, several or noorganizations. To model this, the entity

    Employee needs a relation to the entityOrganization.

    Open the entity Employee from theEntity Services Catalog.

    Expand the node demo.core.registerfrom the Entity Catalog and selectOrganization.

    Add a reference with the button

    A reference has been added.

    Since a employee can belong to morethan one organization, the cardinality ofthe relation has to be changed from 0..1to 0..n.

    (Open the tab page Properties on thelower view and change the value of theproperty Cardinality)

    2.4.5 Define the application services the business logic

    The application service RegisterAppmust now be updated with the new

    functionality and the references to thenew entity.

    Open the RegisterApp from theapplication service node.

  • 8/10/2019 How to GuideforCAF

    56/67

    54

    Navigate to the tab pageDependencies, select the EntityServices Organization and add itto theapplication service by clicking on thebutton:

    The entity is now ready to be used by theapplication service.

    The operation which have to be modifiedare:

    - search for an employee: Done by theWeb Dynpro application at start-up. Thefindby-operation of the new entity has tobe included.

    Some operations are used indirectly bythe Web Dynpro application:

    - create an organization: Entity operation

    - read an organization: Entity operation

    - update an organization: Entity operation

    - delete an organization: Entity operation

    Notice: All these operations have to bedefined, but only the findby and read-operations are actually used.

    To add new operations, navigate to thetab page Operations and press thebutton Add.

  • 8/10/2019 How to GuideforCAF

    57/67

    55

    Select the operation type Access andcheck the options Create, Read,Update and Delete.

    Continue with Next.

    Enter Organization as description andselect the data type Organizationfromthe catalog.

    Leave the permission check Disabled.

    Confirm with Finish.

    As before, you must manually add apredefined exception class to theoperation.

    From the Attributes / Type repository,select ServiceException and add this to

    all 4 operations by pressing the buttonFault.

    The life-cycle operations for theOrganization entity are ready.

    Now, the coding has to be changedslightly.

  • 8/10/2019 How to GuideforCAF

    58/67

    56

    Navigate to the Implementationtabpage.

    1. createOrganization (string).

    Click on this method; add the following

    code to the method between the brackets(you will have to replace the coderetValue=null):

    //@custom code start - createorganization

    retValue = getOrganizationService().create(employeenr);

    //@custom code end - createorganization

    2. readOrganization(string), add:

    (you will have to replace the coderetValue=null):

    //@custom code start - readOrganization

    retValue = getOrganizationService().read(key);

    //@custom code end readOrganization

    3. updateOrganization(Organization) ,add:

    //@custom code start - updateOrganization

    getOrganizationService().update(dS0);

    //@custom code end updateOrganization

    4. deleteOrganization(Organization) ,add:

    //@custom code start - deleteOrganization

    getOrganizationService().delete(dS0);

    //@custom code end deleteOrganization

    5. FindEmployeeByPersonalID() ,change the code to the following:

    Notice: This will be changed in a laterrelease currently it is not possible toautomatically use a reference attribute

    from a parent entity as an input parameter(e.g. employeeref.personalid). Therefore,it all has to be coded manually.

    //@custom code start - FindEmployeeByPersonalIDretValue = getEmployeeService().findByPersonalID(personalID);

    Object[] values = retValue.toArray();Employee[] employee = newEmployee[values.length];for(inti = 0; i < values.length; i++) {

    employee[i] = (Employee) values[i];

    try{java.util.List retValue2 = getOrganizationService().findbyemployeenr(personalID);Object[] values2 = retValue2.toArray();Organization[] organization = newOrganization[values2.length];for(intj = 0; j < values2.length; j++) {

    organization[j] = (Organization) values2[j];employee[i].addOrganizationRef(organization[j].getKey());getEmployeeService().update(employee[i]);

    }}catch(Exception e) {

    com.sap.caf.rt.util.CAFPublicLogger.categoryCAF.log(com.sap.tc.logging.Severity.INFO, location, e);

    }}

    //@custom code end FindEmployeeByPersonalID

  • 8/10/2019 How to GuideforCAF

    59/67

    57

    The coding is now ready. Save allmetadata by pressing the button

    Because the meta-information has nowchanged, it is recommended to manuallygenerate all code before building anddeploying.

    To do so, select Generate All ProjectCodefrom the context menu of theproject root.

    Notice: If you experience problems whenrunning the application like missing tablesor undefined relationsships, this may becaused by incompleted meta-informationat deploy-time. Generate and rebuild yourproject!

    To build the application, select theproject root.

    From the context menu, select

    Development Component and selectBuild from this menu.

    Confirm any pop-ups and wait until thecomponent has been build.

  • 8/10/2019 How to GuideforCAF

    60/67

    58

    The application is now ready to bedeployed.

    To do so, select Deploy to J2EEEngine from the context menu and waituntil all 5 sub-projects are finished.

    The successful result is shown to theright.

    2.4.6 Configuring the external service

    Because you are using external servicesnow, you will have to do someconfiguration work (logon as administratorCTB_ADMIN see chapter 1.3).

    1. Open the URLhttp://localhost:51000/caf

    2. Click Administrative tools and thenExternal Service Configuration

    3. Select the link Service Registry

    4. The new configuration is deployed assap.com/demo.core.register

    5. Select this entry and open thedefinition.

    Select the nodeZ_WS_EMPLOYEE_GETDATA andenter the following entries:

    1. End point Url:http://localhost:51080/sap/bc/soap/rfc

    2. Select Basic authentication3. User/password: admin/admin

    please also refer to chapter 1.3

    4. Save

  • 8/10/2019 How to GuideforCAF

    61/67

    59

    Again as a preview, you could test it withthe CAF service-browser tool.

    1. Open the URLhttp://localhost:51000/caf

    2. Then Test tools and go to ServiceBrowser

    3. Open the application RegisterApp inthe folder demo.core.register

    4. Try it out.

    To test it, do the following:

    1. Create a user: Press New, enter apersonalid 14132and Save

    2. Search for this user: Enter 14132inthe field personalID and pressExecute Query.

    3. Open the related entityorganizationRefon the bottom of thescreen. You should now see the resultfrom the backend (the orgunit).

    2.5. CHANGING THE WEB DYNPRO MODEL

    2.5.1 Generate the Web Dynpro model

    Next thing to do is to update the modelused in the Web Dynpro application.

    Select the project rootand select

    Create Web Dynpro Model from thecontext menu.

  • 8/10/2019 How to GuideforCAF

    62/67

    60

    2.5.2 Change the Web Dynpro application

    Switch to the Web Dynpro Perspectiveby clicking on the button:

    You can see that the CAF Core services(demo_core_register) have beenupdated with the new model forOrganization.

    Open the viewEquipmentRegistryView from thecomponent EquipmentRegistry

  • 8/10/2019 How to GuideforCAF

    63/67

    61

    2.5.3 Change the context values in the Web Dynpro view component

    The new model node organizationshould now be mapped to the localcontext.

    First, you will have to create a new modelnode for the organization.

    Select New > Mode Nodefrom thecontext menu.

    Name the node Organization andconfirm with Finish

    Select Edit Model Binding from thecontext menu of the model node

    Organization.

  • 8/10/2019 How to GuideforCAF

    64/67

    62

    Select organizationRef(AOrganization) within the nodeAEmployee.

    This is the relationship node betweenEmployee and Organization.

    Continue with Next

    Select the attribute orgunit and confirmwith Finish.

    The local organization model is nowbound to the CAF Core entity model.

    The properties and the structure shouldnow look like this:

    2.5.4 Change the UI elements in the Web Dynpro view component

  • 8/10/2019 How to GuideforCAF

    65/67

    63

    Now, the UI elements of the view can bere-designed to incorporate the newinformation.

    Open the tab page Layout

    Change the text of the label to Pleaseregister your equipments.Yourorganizational unit is:

    Then, change the binding of the nextelement toEmployee.Organization.orgunit .

    (Press to access the context viewer)

    2.5.5 Building, deploying and running the application

    The Web Dynpro application is now readyto be deployed along with the CAF Coreproject.

    Navigateback to the CAF perspective

    To build the application, select the

    project root.

    From the context menu, selectDevelopment Component and selectBuild from this menu.

    Confirm any pop-ups and wait until thecomponent has been build.

  • 8/10/2019 How to GuideforCAF

    66/67

    64

    The application is now ready to bedeployed.

    To do so, select Deploy to J2EEEngine from the context menu and waituntil all 5 sub-projects are finished.

    The successful result is shown to theright.

    You can run the application directly fromthe Web Dynpro Explorer.

    Select Run from the context menu of theApplication RegisterApp and test it asan anonymous user (guest)

    Notice: The master application(master.core.register) has beenintegrated into the Guided ProceduresFirstDay and is also accessible from theportal workset Composite Toolbox =>CAF Core App.

    Be aware that only for users alsoavailable in the backend-system (as withMiller, Jamie 14132) the organizational

    unit will be shown!

    Notice: You can of course also run theapplication from the Web Dynpro ContentAdministration.

  • 8/10/2019 How to GuideforCAF

    67/67

    and the result is:


Recommended