cancel
Showing results for 
Search instead for 
Did you mean: 

Read Cookie in WebDynpro Java

Former Member
0 Kudos

Hello,

I have a WebDynpro Application and I want to store some user specific personalization data in a client cookie...

Two question:

Is there a better way to store user specific personalization data?

How can I set and get cookies from the client?

Thanks!

Johannes

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

I think this is persistent

please if anybody have used it tell me about it

try{
IWDClientUser LoggedUser = WDClientUser.getCurrentUser();
 
IUserMaint User = UMFactory.getUserFactory().getMutableUser(LoggedUser.getSAPUser().getUniqueID()); 
 
//To get the values of the custom attribute ..
String Value[] = User.getAttribute("com.sap.security.core.usermanagement", "Flag");
 
 
if (Value == null || Value.length == 0) {
	User.setAttribute("com.sap.security.core.usermanagement", "Flag",new String[]{"BorderColor=pink"} );
	User.commit();
} else {
 
	//Sample code for getting the value of theattribute 
	for (int i = 0; i < Value.length; i++) {
		wdComponentAPI.getMessageManager().reportSuccess("Value of the custom Att" + Value<i>);
	}
}
 
wdComponentAPI.getMessageManager().reportSuccess("Stored attribute::"+((String[])User.getAttribute("com.sap.security.core.usermanagement", "Flag"))[0]);
}catch...

siarhei_pisarenka3
Active Contributor
0 Kudos

This is definitely the most funny solution for reading/writing cookies in WebDynpro applications ))

Former Member
0 Kudos

Honestly,

I kinda liked this last implementation code. This thread is old, does anyone has any knowledge how would UME save this "Attributes" for an user?

Not sure what is funny about it. Of course it's not a "Cookie" but I still didn't understand where the funny thing is. Can you please explain?

Regards,

Daniel

siarhei_pisarenka3
Active Contributor
0 Kudos

Hi Daniel

I mean that the solution is funny when we are talking about Cookies. Of course the code itself is not funny, but rather good

My point is the following. UME User Attributes, as I know, shall describe additional characteristics of the user himself. For example, in some organization an user can have such attributes as Position, Age, Sex, etc. These attributes do not depend on any application.

From other side Cookies is different thing. Let me give the following definition - Cookies are set of user preferences for a particular web-application. Same user may have many different preferences for many applications running on same server.

From the point of view I think that storing application specific user properties as UME User Attributes is incorrect.

In addition, UME in NW Java can be configured in several ways. For example, Java UME can reference LDAP directory or ABAP UME (dual ABAP+Java stack) as user storage. In the case I'm not sure if the code for setting user attributes will work.

@Daniel, please share your thoughts about this in the new thread that I created regarding the problem:

Thanks and Regards,

Siarhei

Answers (5)

Answers (5)

Former Member
0 Kudos

How can I store it in the portal database?

Regars,

Johannes

Former Member
0 Kudos

Hi,

Do you have any backend database in your application.

For example Oracle, R/3 etc..

Store in that database.

For example if you are using Oracle databse

Then using JDBC you can insert the data into database.

If your backend is SAP R/3

Then using Adaptive RFC model you can make RFC call to store the data in R/3 sytem.

Regards,

Charan

Former Member
0 Kudos

Hello,

what about setting a cookie?

Regards,

Johannes

Former Member
0 Kudos

Hi Johannes,

If you want persistance after expiring the session also then why dont you store that data in Database.

In client session you can store complex data objects also. Array of Java class objects.

As per my knowledge there is no better way other than client session / database.

Regards,

Charan

Former Member
0 Kudos

Hello,

thanks for the fast reply!!

The solution works als long as I don't close my Internet Explorer. I need a solution that stores the personalization data longer...

Thanks!

Johannes

Former Member
0 Kudos

Hi,

You can use the below code:


 WDScopeUtil.put(WDScopeType.CLIENTSESSION_SCOPE,"KEY","Value");
 WDScopeUtil.get(WDScopeType.CLIENTSESSION_SCOPE,"KEY").toString();
 

Regards,

Charan

Former Member
0 Kudos

Hi,

You can maintain the clinet side data in session.

Code to maintain the client side data in session

String test1 = wdContext.currentContextElement().getTest1();
String test2 = wdContext.currentContextElement().getTest2();

IMaintainScope maintainer = Utils.getScopeMaintainer(WDScopeType.CLIENTSESSION_SCOPE);
maintainer.getScope().put("Test1", test1);
maintainer.getScope().put("Test2", test2);

//Retrieving the data from session

if(maintainer.getScope().get("Test1") != null)
{
String test1= maintainer.getScope().get("Test1").toString();	
}
if(maintainer.getScope().get("Test2") != null)
{
String test2= maintainer.getScope().get("Test2").toString();	
}

Hoe this helps you...

Regards,

Saleem