cancel
Showing results for 
Search instead for 
Did you mean: 

Urgent: Get portal user in a web dynpro

Former Member
0 Kudos

Hi all!

I have an urgent matter. I am developing a specific portal service in web dynpro. Does anyone of you know how can i know the user using this service. To be more explicit, this service is used to diplay the information concerning the portal user. I am using a BAPI to get this information from the backend. One of the imports parameters of this BAPI is the userID of the one requesting this information. How can I get this userID.

Your help is really appreciated.

Thanks a lot!

Hajar

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Thank you both a lot!!

Your answers are very helpful. Since this is my first experience developing in web dynpro where do i need exactly to put these lines of code? should they be included in one of the component methods? I would be glad if someone can provide me with an example.

Thanks a lot again!

Hajar

achim_hauck2
Active Contributor
0 Kudos

you could place them in the wdDoInit()-method of the/a Controller and save the UserID in a Context-Element of type String. You can make this Context-Element available to other Views etc. via Mapping.

Maybe it would be useful to put a try/catch-block around the mentioned code, if the User wasn't authenticated before.

kr, achim

Example:


try{
IWDClientUser user = WDClientUser.getCurrentUser();
wdContext.currentContextElement().setUserID(user.getSAPUser().getUniqueName().toUpperCase());
catch (Exception ex) {
...
}

you have to add the com.sap.security.api.jar to your build path of your aplication.

Message was edited by: Achim Hauck

pravesh_verma
Active Contributor
0 Kudos

Hi,

Ya, Achmin is right!! Putting it in Controller can be useful. but then take care of the mapping of the attributes from the context node of the controller with the view Context.

If you have only 1 view then you can do this directly in the view code. You will be saved from the mapping of the controller attributes from the view attributes. But the recommended methos is always to put the processing logic in the controller's code.

You have to go to <b>Data Modeler</b>, and then create a Data link of the controller and the view and then select the attribute which has the value of the user from controller context.

Finally you will have the attribute in view controller which will have the same value as in the component controller.

I hope this helps you.

Regards

Pravesh

vijayakhanna_raman
Active Contributor
0 Kudos

Hi Hajar,

If you want to get the user when the application starts, then put the code in the wdDoInit() method of the view controller. Otherwise, you can also get the user on the action button click. Get the value as String and store this value in the context attribute.

String user = <get the user>

wdContext.currentContextElement.setAttr(user);

Regards,

Vijayakhanna Raman

Answers (3)

Answers (3)

Former Member
0 Kudos

Thanks a lot your answers were very helpful!

Hajar

achim_hauck2
Active Contributor
0 Kudos

Hajar,

you can get it like this:


IWDClientUser user = WDClientUser.getCurrentUser(); 
IUser iUser = user.getSAPUser();

the iUser-Object has many .get-Methods, one of them is the UserID.

kr, achim

pravesh_verma
Active Contributor
0 Kudos

Hi Hajar,

The current user can than be retrieved with

<b>WDClientUser.getCurrentUser()</b>

and you get an IUser object with

<b>WDClientUser.getCurrentUser().getSAPUser()</b>

I hope this helps you..

Regards

Pravesh

PS: Please consider rewarding points if helpful or solved.