Hi Fred,

On Apr 4, 2007, at 3:10 PM, Fred Shurtleff wrote:

Hello,

I have a basic question on how to access the logged in user for later use in updates. After authenticating a user I enter him into the session, but when I later try to retrieve this user in another page, it fails(returns null).

So in my main page I record the user as follows:

if (_password.equals(password)) { EOEnterpriseObject user = EOUtilities.objectMatchingKeyAndValue(session ().defaultEditingContext(), "User", "name", username); // set the session.user session ().takeValueForKey(user, "user");

And on another page to add a new transaction which needs the user relation attribute(as a foreign key):

EOEnterpriseObject user = (EOEnterpriseObject) valueForKeyPath ("session.user"); // user evals to null???

Try changing this to:

EOEnterpriseObject user = (EOEnterpriseObject)session().valueForKey ("user");

valueForKeyPath is useful, but I don't think it can do what you're asking of it here.

purchase.addObjectToBothSidesOfRelationshipWithKey(user, "user");

The save fails because user is a required attribute. And I'm not sure if I am not properly storing the user in the session, or not properly retrieving the user from the session.

Can anyone see what I am doing wrong or suggest another approach?

TIA

Personally, I usually make currentUser an actual variable in Session. (Private, with public accessor methods, of course! ;-)

Regards,
Mark
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to