Re: How to Retrieve Session User?
Re: How to Retrieve Session User?
- Subject: Re: How to Retrieve Session User?
- From: Mike Schrag <email@hidden>
- Date: Wed, 4 Apr 2007 16:45:04 -0400
PERSONALLY, I'd stop all this KVC funnybusiness. It has its place
and it's really powerful, but you're making your life way obnoxious.
Let Java do its job and just call methods on things -- there are LOTS
of benefits of this. Define a proper user field on your Session
class and do setUser(..) and user() to retrieve it.
On Apr 4, 2007, at 4:40 PM, Fred Shurtleff wrote:
Mark - I understand where you are coming from, and did try your
suggestion. But I still am NOT getting a user EO instance (I get
null per the debugger).
Actually I checked the WO docs and both valueForKeyPath AND
valueForKey are valid methods of the Session class. Problem is what
is the correct syntax. The docs say object.valueForKey(string), and
your suggestion provided the object part (ie session()) (I also
tried your input + valueForKeyPath but Eclipse complained about 'no
such key = session')
So I still am at a loss on how to retrieve a user EO from the
session. :-(
But thanks for your help/input!
Mark Morris wrote:
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@hidden)
Help/Unsubscribe/Update your Subscription:
40mdimension.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden