Show TOC Entering content frame

Procedure documentation Modifying the Web Dynpro Model Locate the document in its SAP Library structure

Use

You must modify certain aspects of the generated Web Dynpro model before it can be properly integrated into CAF. This procedure is necessary to guarantee the communication between the development component project created with Composite Application Services (CAS), the Web Dynpro model, and the CAF environment.

Prerequisites

You have built and generated the DC project and all other projects automatically created in CAS. You have launched SAP NetWeaver Developer Studio.

Creating Contexts

In order to map a generated Web Dynpro model to the user interface application for the design time model usage, you need to create a public project which contains the generated model with user interfaces. You do this by creating a public part, which contains the java package tree that corresponds to the model package.

Note

You should create the public part only once for every model.

Creating the Public Part

 

...

       1.      Choose Entities.

The Entities wizard opens.

       2.      Click Java Package Tree from the Select Entity Type window and choose Master Data from the Select Entities pane.

The model package has the following template: <provider_package>.<application_name>.services.<model_name>

       3.      Choose Finish.

Setting Up Dependencies and References

In order to use the generated model in the Web Dynpro project, you need to add dependencies and shared references.

 

 

       1.      Choose Add Dependency and select types_compilation.

You are specifying a set of dependencies between development components and public parts of Web Dynpro. In DC Reference, you can see the reference information such as dictionary name, vendor, and which public part was referenced.

       2.      In Dependency Type choose one or more of the following and choose Finish:

¡        Design Time:   This is needed for special editors only.

¡        Build Time:      Needed for compilation

¡        Deploy time:    This refuses deployment if dependant is missing.

¡        Run Time:       This indicates if one deployable uses another one.

       3.      To create sharing references, choose Web Dynpro References and OK.

The shared references appear in the Sharing references tab page.

       4.      Add the generated model to the used models lists of the UI project.

Creating a Custom Controller

 

 

       1.      In your Web Dynpro project in the Explorer view, create a custom controller by launching the New Custom Controller wizard with Web Dynpro ®   Web Dynpro Components  ® Custom Controllers and clicking the secondary mouse button.

You can see a tree representing the generated model in the Diagram View window.

       2.      Enter a name and package and choose Finish.

       3.      Select the controller with the secondary mouse button and choose Edit.

       4.      Select a model node corresponding to the query and choose Next.

       5.      Select the query node and all subnodes and choose Finish.

Application Data Visualization

To further proceed with the Web Dynpro model, you must first bind context nodes to UI elements. You use this assignment to bind the UI element to the context of the associated view controller.

Binding UI Elements

 

 

       1.      Create a new view and choose Edit to edit the context.

The context should reflect the custom controller context.

       2.      Create a new model node and choose Edit context binding with the secondary mouse button.

       3.      Select the custom controller context and all its subnodes and choose Ok.

Query results are displayed at the top of the table, at the bottom you can see the related aspect rows. The top input field represents the input parameters for query.

       4.      Select the input field from the view and choose the Properties tab page.

You do this to bind the corresponding context node to the input query parameter.

       5.      Select  This graphic is explained in the accompanying text and choose objectKey from the Context Viewer window. Choose Ok.

The RelatedKey field and the Associate/Unassociate buttons are used to manage the relation between Qitem and QbucketMD objects. The RelatedKey field is bound to the newly created value node RelatedKey.

Runtime Model Usage

 

 

       1.      Include the following code to implement runtime usage:

Syntax documentation

IServiceFacade serviceFacade = null;

IServiceModule mainService = null;

IQuery query = null;

 

public void wdDoInit()

{

//@@begin wdDoInit()

wdContext.getContext().reset();

serviceFacade = CAFServiceFactory.getServiceFacade (CQMMasterdataDefinition.class);

mainService = serviceFacade.getServiceModule (CQMMasterdataDefinition.S_QITEM);

query = mainService.createQuery (CQMMasterdataDefinition.Q_QITEM_FINDBYOBJECTKEY);

wdContext.nodeQuery().bind((QQItemFindByobjectKey) query);

//@@end

       2.      Include the following code to implement the associateRelated, executeQuery, and unassociateRelated actions:

Syntax documentation

//@@begin javadoc:executeQuery()

/** Declared method. */

//@@end

public void executeQuery( )

{

//@@begin executeQuery()

query.execute();

wdContext.nodeResult().invalidate();

//@@end

}

//@@begin javadoc:associateRelated()

/** Declared method. */

//@@end

public void associateRelated( )

{

//@@begin associateRelated()

String relatedKey = wdContext.currentContextElement().getRelatedKey();

if(relatedKey == null || relatedKey.equals("")) {

return;

}

IServiceModule coursesModule = serviceFacade.getServiceModule (CQMMasterdataDefinition.S_QBUCKETMD);

IKeyList relatedAspectKeyList = coursesModule.createKeyList (CQMMasterdataDefinition.A_QBUCKETMD_PK);

Key relatedAspectKey = coursesModule.createKey (CQMMasterdataDefinition.A_QBUCKETMD_PK, new String[]{relatedKey});

relatedAspectKeyList.add(relatedAspectKey);

IAspect relatedAspect = coursesModule.getAspect (CQMMasterdataDefinition.A_QBUCKETMD, relatedAspectKeyList);

AQItem mainAspectRow = wdContext.nodeResult().currentResultElement().modelObject();

mainAspectRow.setRelatedBucketMd((AQBucketMd) relatedAspect.getAspectRow(0));

wdContext.currentContextElement().setRelatedKey("Result : " + true);

mainService.sendChanges();

serviceFacade.save();

wdContext.nodeResult().invalidate();

//@@end

}

//@@begin javadoc:unassociateRelated()

/** Declared method. */

//@@end

public void unassociateRelated( )

{

//@@begin unassociateRelated()

AQItem mainAspectRow = (AQItem) wdContext.nodeResult().currentResultElement().model();

AQBucketMd relatedAspectRow = wdContext.nodeRelatedAspect().currentRelatedAspectElement().modelObject();

boolean result = mainAspectRow.removeRelatedBucketMd(relatedAspectRow);

wdContext.currentContextElement().setRelatedKey("Result : " + result);

mainService.sendChanges();

serviceFacade.save();

wdContext.nodeResult().invalidate();

//executeQuery();

//@@end

}

Note

The above described code ensures that all data is retrieved via the defined bindings and that all tables are populated with the required data. This executes your query.

Utility Classes

For each model data object with DB persistence, there is a set of common tasks like retrieving an object by its ID. Such common methods are already implemented in special utility classes (for example name pattern <entity_name>Utils). In view of these classes, the associate method can be simplified as follows:

Syntax documentation

public void associateRelated( )

{

//@@begin associateRelated()

String relatedKey = wdContext.currentContextElement().getRelatedKey();

if(relatedKey == null || relatedKey.equals("")) {

return;

}

AQItem mainAspectRow = wdContext.nodeResult().currentResultElement().modelObject();

mainAspectRow.setRelatedBucketMd(QBucketMdUtils.qBucketMdByGuid(relatedKey));

wdContext.currentContextElement().setRelatedKey("Result : " + true);

mainService.sendChanges();

serviceFacade.save();

wdContext.nodeResult().invalidate();

//@@end

}

Result

You have modified the Web Dynpro project and can deploy all projects to the J2EE engine.

Leaving content frame