Fetching User Details from the
Portal and Displaying it in Web
Dynpro with Authentication in the
Portal
Applies to:
SAP NetWeaver Web Dynpro. For more information, visit the Portal and Collaboration homepage.
Summary
This article contain the simple steps about how to create a simple Web Dynpro application that fetches the
user details in Web Dynpro when logged on to the Portal.
Author: Nikhil B. Tapkir
Company: L&T Infotech
Created on: 22 August 2008
Author Bio
Nikhil Tapkir is working as a Web Dynpro consultant in L&T Infotech Pvt. Ltd. since 9 months
ago.
.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 1
Fetching User Details from the Portal and Displaying it in Web Dynpro with Authentication in the Portal
Table of Contents
Steps...................................................................................................................................................................3
Steps for Authentication ..................................................................................................................................3
Steps for Fetching User Details ......................................................................................................................9
Steps for Creating View Layout ....................................................................................................................11
Result................................................................................................................................................................13
Related Content................................................................................................................................................14
Disclaimer and Liability Notice..........................................................................................................................15
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 2
Fetching User Details from the Portal and Displaying it in Web Dynpro with Authentication in the Portal
Steps
Steps for Authentication
We start by creating a Web Dynpro Project
Click on finish.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 3
Fetching User Details from the Portal and Displaying it in Web Dynpro with Authentication in the Portal
Now In the project right click on application. Create application.
Click on Next until you reach the following screen
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 4
Fetching User Details from the Portal and Displaying it in Web Dynpro with Authentication in the Portal
Click on finish. You have created a component, and a view embedded in the window.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 5
Fetching User Details from the Portal and Displaying it in Web Dynpro with Authentication in the Portal
The project structure in Web Dynpro explorer would look as follows.
Now in the project go to applications double click on PortalLogonUserApp.click on the Tab Application
Properties.
Click on New. On the Next screen, press the browse button.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 6
Fetching User Details from the Portal and Displaying it in Web Dynpro with Authentication in the Portal
Select Authentication. Press Ok.
Now set the Value to true. And click on finish.
The result of these steps will be that whenever you will run this application, before accessing the application,
it requires you to provide a valid portal login id and password. Only a valid user can access the application.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 7
Fetching User Details from the Portal and Displaying it in Web Dynpro with Authentication in the Portal
Note: You need to add the jar files com.sap.security.api.jar. and com.sap.security.api.perm.jar.
We add these files by Right click on the project. Select Properties. Select Java Build Path.
Then press the button Add External Java files and browse to the location of these files. After adding both the
jar files click on OK.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 8
Fetching User Details from the Portal and Displaying it in Web Dynpro with Authentication in the Portal
Steps for Fetching User Details
Now In the project under project click on component controller under PortalLogonUserApp press on to the context
Tab.
In the context tab, create the following context.
**All the context are of string type.
Now double click on the PortalLogonUserApp it will open the Daigram view.
Carry out the context mapping between the component controller and the view controller as shown below
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 9
Fetching User Details from the Portal and Displaying it in Web Dynpro with Authentication in the Portal
Now click on to component controller under PortalLogonUserApp press on the implementation tab and write
the following lines of coding in the wdDoInit() method.
try {
IWDClientUser clientUser = WDClientUser.getCurrentUser();
IUser user = clientUser.getSAPUser();
String displayname = user.getDisplayName();
wdContext.currentContextElement().setDisplayname(displayname);
String uniquename = user.getUniqueName();
wdContext.currentContextElement().setUniquename(uniquename);
String firstname= user.getFirstName();
wdContext.currentContextElement().setFirstname(firstname);
String uid= user.getUniqueID();
wdContext.currentContextElement().setUid(uid);
String jobtitle= user.getJobTitle();
wdContext.currentContextElement().setJobtitle(jobtitle);
String lastname=user.getLastName();
wdContext.currentContextElement().setLastname(lastname);
}
catch (WDUMException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
** WDUMException would generate an error. Put the mouse cursor over it Right click and go to Source and
Then click on organize imports.the following import would be added
import com.sap.tc.Web Dynpro.services.sal.um.api.WDUMException;
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 10
Fetching User Details from the Portal and Displaying it in Web Dynpro with Authentication in the Portal
Steps for Creating View Layout
Now create the following layout in the PortalLogonUserAppView.
The outline of the view
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 11
Fetching User Details from the Portal and Displaying it in Web Dynpro with Authentication in the Portal
Now carry out the mapping of the context with their respective input field
UI element Property Value
displaynameinput Value
firstnameinput Value
lastnameinput Value
jobtitleinput Value
uniquenameinput Value
uidinput Value
The view would look as
Now right click on PortalLogonUserApp and deploy the application.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 12
Fetching User Details from the Portal and Displaying it in Web Dynpro with Authentication in the Portal
Result
A logon Screen would appear. A logon Screen would appear. Enter the valid logon details.
The user details are displayed.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 13
Fetching User Details from the Portal and Displaying it in Web Dynpro with Authentication in the Portal
Related Content
Users And User Management
System logon
UI development with Web Dynpro
For more information, visit the Portal and Collaboration homepage.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 14
Fetching User Details from the Portal and Displaying it in Web Dynpro with Authentication in the Portal
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.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
© 2008 SAP AG 15