• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: An Apps Session from a Framework [SOLUTION]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: An Apps Session from a Framework [SOLUTION]


  • Subject: Re: An Apps Session from a Framework [SOLUTION]
  • From: "Jonathan Fleming" <email@hidden>
  • Date: Fri, 30 Apr 2004 14:00:12 +0100

From: "Jonathan Fleming" <email@hidden>
To: email@hidden, email@hidden, email@hidden, email@hidden
CC: email@hidden
Subject: Re: An Apps Session from a Framework [SOLUTION]
Date: Fri, 30 Apr 2004 13:38:06 +0100


Hello Guys,

thanks to you all for your responses on this, the options that you left available to me was an eye opener as well as a head scratcher....

I chose to go with Chuck's implementation as this suits and covers other classes that I want to put in the framework that have references to a Session:
Chuck Hill, email@hidden, wrote:
Put a WOSession sub-class in the framework, say UserSession. Make this implement setUser, setEntry etc etc. Cast to this session in the FW. In the Application make Session extend UserSession instead of WOSession. Or create an interface with setUser, setEntry etc etc. and cast to this and have Session implement the interface.

but like Jonathan 'Wolf' Rentzsch said it's good to have other options such as using KVC:
       Session sess = (Session)session();
       sess.setUser(null);
       sess.setEntry(null);
       sess.setUsername(null);
       sess.terminate();

WOSession sess = session(); session.takeValueForKey( null, "user" ); session.takeValueForKey( null, "entry" ); session.takeValueForKey( null, "username" ); sess.terminate();


The head scratcher was me thinking why did't I simply do that which Anjo said:
Why not do the more obvious thing and move that code to Session.terminate()? That would mean your logout >component would be able to call

session().terminate()

without referencing the other class.
The answer was as my number of apps are growing now, I did want to keep copying and pasting this code in every application's Session class. But, yes it has it's "pros" as well as it's "cons" as does most things.

And lastly, Tom Blenko said:
I've always done this by implementing a Session.logout() method which calls Session.terminate() and >returns a WORedirect to whatever the Main page is. Similar to what Anjo suggests. logout() is >implemented in the Session because it isn't a separate component but it is called from multiple pages.

I haven't done this as a separate component in a framework. If you want it in a framework, subclass >from Session in the framework and implement logout() there. Then subclass from that subclass in the >application (what Chuck said).
My code does return a WORedirect to the main page, here's the class which may be of use to others:

// Copyright ) Jonathan Fleming Sat Dec 14 09:49:53 GMT 2002

import com.webobjects.foundation.*;
import com.webobjects.appserver.*;

public class LogoutComponent extends WOComponent {

   public LogoutComponent(WOContext context) {
       super(context);
   }

public WOComponent logOut() {
Session sess = (Session)session();
sess.setUser(null);
sess.setPassword(null);
sess.setUsername(null);
sess.terminate();
WORedirect redirect = (WORedirect)pageWithName("WORedirect");
String host = "http://"+ this.context().request().headerForKey("host");
Oops this is a mistake, I was changing things while I was posting, it should of course be:
String host = this.context().request().headerForKey("host");
redirect.setUrl( "http://"+host+context().urlWithRequestHandlerKey("wa", null, null) );

NSLog.out.appendln( "===\r Logout's Redirection URL: " +
"http://"+host+context().urlWithRequestHandlerKey("wa", null, null) );


       return redirect;
   }

}

Cheers everyone
Jonathan :^)

posts from:
Jonathan 'Wolf' Rentzsch <email@hidden>,
Chuck Hill <email@hidden>,
Anjo Krank <email@hidden>,
Tom Blenko <email@hidden>

_________________________________________________________________
Sign-up for a FREE BT Broadband connection today! http://www.msn.co.uk/specials/btbroadband
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.



_________________________________________________________________
Use MSN Messenger to send music and pics to your friends http://www.msn.co.uk/messenger
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.



  • Prev by Date: Re: EOF & pgSQL join syntax
  • Next by Date: Re: deploy webobjects in servlet
  • Previous by thread: Re: An Apps Session from a Framework [SOLUTION]
  • Next by thread: automated testing of site
  • Index(es):
    • Date
    • Thread