Create UWL Screen Using Web Dynpro Java API

14
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com © 2011 SAP AG 1 Create UWL Screen using Web Dynpro Java API Applies to: SAP Net Weaver Portal 7.0. For more information, visit the Web Dynpro Java homepage . Summary Using UWL API in Web Dynpro Java to create a custom screen for viewing/executing workflow tasks. Author: Gaurang Dayal Company: MindTree Ltd. Created on: 29 March 2011 Author Bio Gaurang Dayal is working as a SAP Netweaver Consultant with MindTree Ltd.

description

Create UWL Screen Using Web Dynpro Java API

Transcript of Create UWL Screen Using Web Dynpro Java API

Page 1: Create UWL Screen Using Web Dynpro Java API

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 1

Create UWL Screen using Web

Dynpro Java API

Applies to:

SAP Net Weaver Portal 7.0. For more information, visit the Web Dynpro Java homepage.

Summary

Using UWL API in Web Dynpro Java to create a custom screen for viewing/executing workflow tasks.

Author: Gaurang Dayal

Company: MindTree Ltd.

Created on: 29 March 2011

Author Bio

Gaurang Dayal is working as a SAP Netweaver Consultant with MindTree Ltd.

Page 2: Create UWL Screen Using Web Dynpro Java API

Create UWL Screen using Web Dynpro Java API

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 2

Table of Contents

Prerequisites ....................................................................................................................................................... 3

Download Required Archives ............................................................................................................................. 3

Project Development .......................................................................................................................................... 3

Creating project in SAP NWDS ....................................................................................................................... 3

Adding the External Libraries and References ............................................................................................... 5

Configuring the view ........................................................................................................................................ 6

Methods to populate and execute the Workflow tasks ................................................................................... 8

Bind actions to the UI elements .................................................................................................................... 12

Related Content ................................................................................................................................................ 13

Disclaimer and Liability Notice .......................................................................................................................... 14

Page 3: Create UWL Screen Using Web Dynpro Java API

Create UWL Screen using Web Dynpro Java API

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 3

Prerequisites

Basic Knowledge of Web Dynpro Java.

UWL has been configured as per the note 1133821.

WebflowConnector is enabled.

Download Required Archives

Please download the following jar files and add them as external jars to the project.

File Name Location

bc.uwl.service.api_api.jar \com.sap.netweaver.bc.uwl.plugin_1.0.0\lib

bc.uwl.service.api_core.jar \com.sap.netweaver.bc.uwl.plugin_1.0.0\lib

com.sap.security.api.jar \com.sap.security_2.0.0\lib

Project Development

Creating project in SAP NWDS

Open SAP Netweaver Developer Studio

Go to File New Web Dynpro Project

Enter the project name as shown below and click on Finish.

Page 4: Create UWL Screen Using Web Dynpro Java API

Create UWL Screen using Web Dynpro Java API

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 4

Expand the newly created project structure and right Click on Applications Create Application

Enter the application name and package name in the subsequent wizard screen and click on Next.

Create a new Web Dynpro component and click on Next.

Enter the component name and package details and click on Finish.

Page 5: Create UWL Screen Using Web Dynpro Java API

Create UWL Screen using Web Dynpro Java API

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 5

Adding the External Libraries and References

Right Click on the Project name and select properties.

Go to Java Build Path Libraries Add External JARs.

Select the jar files downloaded (as shown in the section above) and click on Open. The jar files will appear in the Java Build Path.

Click on OK. The JARs have now been added to the class path. Please refer to the screen shot below:

Page 6: Create UWL Screen Using Web Dynpro Java API

Create UWL Screen using Web Dynpro Java API

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 6

Add the following reference under Web Dynpro References Library References Add – sap.com/tc~kmc~bc.uwl~api.

Configuring the view

Inside the project structure go to Web Dynpro Components CustomUWLApp Views CustomUWLAppView

Right click on the view name and select Edit, Go to the Context Tab. Under the parent node Context, create a Value node ApprovalInbox. Create Value attributes under this node as shown below:

Page 7: Create UWL Screen Using Web Dynpro Java API

Create UWL Screen using Web Dynpro Java API

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 7

All the Attributes will be of type string except “Item”. Right click on the attribute “Item” and select properties. Edit the property category type as shown below:

Click on Layout of the View and go to the outline tab.

Right Click on RootUIElementContainer and select Apply Template.

Select the Table template from the template selection wizard as shown below

Page 8: Create UWL Screen Using Web Dynpro Java API

Create UWL Screen using Web Dynpro Java API

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 8

Click on Next and select the node ApprovalInbox in order to bind it to the Table.

Right click on the table and select properties. Edit the property selectionMode and set it to single.

Methods to populate and execute the Workflow tasks

Click on the Methods tab and add a method getWorkItems.

Page 9: Create UWL Screen Using Web Dynpro Java API

Create UWL Screen using Web Dynpro Java API

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 9

Similarly add another method for executing tasks – executeWorkItems. Pass a parameter of the type com.sap.tc.webdynpro.progmodel.api.IWDNodeElement

Now add two actions

o refreshInbox, which will refresh/reload the inbox.

o executeWorkItem, which will open the task and help the user to execute the work item.

For the action executeWorkItem add a parameter of the type com.sap.tc.webdynpro.progmodel.api.IWDNodeElement

This is how the Methods and Actions tab finally look like

Page 10: Create UWL Screen Using Web Dynpro Java API

Create UWL Screen using Web Dynpro Java API

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 10

Following piece of code is for each of the methods and actions respectively

a) Method - getWorkItems()

//@@begin getWorkItems()

wdContext.nodeApprovalInbox().invalidate();

try {

IUWLService uwlService =

(IUWLService) WDPortalUtils.getServiceReference(

IUWLService.ALIAS_KEY);

UWLContext myContext = new UWLContext();

IWDClientUser user;

user = WDClientUser.getLoggedInClientUser();

IUser currentUser = user.getSAPUser();

myContext.setUser(currentUser);

uwlService.beginSession(myContext,60);

IUWLSession mySession =

uwlService.getUwlSessionForWebDynproClient(myContext);

IUWLItemManager itemMan = uwlService.getItemManager(myContext);

QueryResult result =

itemMan.getItemsForItemType(

myContext,

ItemType.UWL_ITEM_TASK,

null,

null);

ItemCollection coll = result.getItems();

List l = coll.list();

Iterator iter = l.iterator();

while (iter.hasNext()) {

Item item = (Item) iter.next();

IPrivateCustomUWLAppView.IApprovalInboxElement data =

wdContext.nodeApprovalInbox().createApprovalInboxElement();

data.setItem(item);

data.setSubject(item.getSubject());

data.setDescription(item.getDescription());

if(!(item.getStatus()!=null))

{

data.setStatus("Not Available");

}

else

{

data.setStatus(item.getStatus().getText());

}

data.setCreatorId(item.getCreatorId());

data.setCreatedDate(item.getCreatedDate().toString());

data.setLaunchItem(itemMan.getActionUrl(myContext,item.getInternalId(),"launchSAPA

ction"));

wdContext.nodeApprovalInbox().addElement(data);

} catch (UWLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

//@@end

Page 11: Create UWL Screen Using Web Dynpro Java API

Create UWL Screen using Web Dynpro Java API

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 11

b) Method - executeWorkItems( com.sap.tc.webdynpro.progmodel.api.IWDNodeElement item )

//@@begin executeWorkItems()

try {

IUWLService uwlService =

(IUWLService) WDPortalUtils.getServiceReference(

IUWLService.ALIAS_KEY);

UWLContext myContext = new UWLContext();

IWDClientUser user;

user = WDClientUser.getLoggedInClientUser();

IUser sapUser = user.getSAPUser();

myContext.setUser(sapUser);

IUWLSession mySession =

uwlService.getUwlSessionForWebDynproClient(myContext);

IUWLItemManager itemMan =

uwlService.getItemManager(myContext);

Item notifItem = (Item) item.getAttributeValue("Item");

WDPortalNavigation.navigateAbsolute(wdContext.currentApprovalInboxElement().getLaunch

Item(),WDPortalNavigationMode.SHOW_HEADERLESS_PORTAL,"width=80%,height=80%,toolbar=no

,location=no,status=no,tabs=no",null,null);

getWorkItems();

} catch (UWLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

wdComponentAPI.getMessageManager().reportSuccess(""+e.getCause());

}

//@@end

c) Call the method getWorkItems in the hook method wdDoInit() so that the default tasks appear on page load.

d) Finally call method getWorkItems from onActionrefreshInbox and call executeWorkItems from onActionexecuteWorkItem.

Page 12: Create UWL Screen Using Web Dynpro Java API

Create UWL Screen using Web Dynpro Java API

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 12

Bind actions to the UI elements

Bind the action onActionexecuteWorkItem to the onLeadSelect property of the table.

Next you can either create a timed trigger and bind it to onActionrefreshInbox to refresh the table automatically after a given interval of time or create a refresh button and bind to onActionrefreshInbox in order to refresh the inbox manually.

In this example we will create a timed trigger.

The above screen shot shows the properties of a time trigger UI element which will refresh the table automatically after the period mentioned in the delay property element.

This is it…Run the application now and the Workflow items will appear for the logged in user as shown below:

Page 13: Create UWL Screen Using Web Dynpro Java API

Create UWL Screen using Web Dynpro Java API

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 13

Related Content

UWL Configuration

Changing the Look of UWL User Interface

Flashy UWL

For more information, visit the Web Dynpro Java homepage

Page 14: Create UWL Screen Using Web Dynpro Java API

Create UWL Screen using Web Dynpro Java API

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 14

Disclaimer and Liability Notice

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

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

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