• 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: Logout and localization problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Logout and localization problem


  • Subject: Re: Logout and localization problem
  • From: Chuck Hill <email@hidden>
  • Date: Mon, 10 Apr 2006 09:24:35 -0700

Hi Miguel,

Suggestions below.

On Apr 8, 2006, at 8:55 AM, Miguel Arroz wrote:

Hi!

We have an application where the preferred user language is stored in his account. So, he may see the application in English, but as soon as he logs-in, the app switches to the language he choose before. We do this by removing his language from the session language list, and adding it again as the first one.

I'm implementing Logout now. To implement Logout, I have used code from Practical WebObjects book:

  public WOComponent logout() {
        NSMutableDictionary arguments = new NSMutableDictionary();
        arguments.setObjectForKey(Boolean.FALSE, "wosid");

session().terminate();
WORedirect mainPage = (WORedirect) pageWithName("WORedirect");
mainPage.setUrl(context().directActionURLForActionNamed ("logout", arguments));


        return mainPage;
    }

When using this, it's obvious that, whatever the language was before, the Logout page will appear in english. So, I did a small modification:

public WOComponent logout() {
NSMutableDictionary arguments = new NSMutableDictionary();
arguments.setObjectForKey(Boolean.FALSE, "wosid");
arguments.setObjectForKey(session().languages ().objectAtIndex(0), "language");


session().terminate();
WORedirect mainPage = (WORedirect) pageWithName("WORedirect");
mainPage.setUrl(context().directActionURLForActionNamed ("logout", arguments));


        return mainPage;
    }

  And, in DirectAction, I tried this:

public WOActionResults logoutAction() {
String language = (String)request().formValueForKey ("language");
changeLanguage(language);
return pageWithName("LogoutComponent");
}


public void changeLanguage(String newLanguage) {
NSMutableArray languagesArray = new NSMutableArray (this.languages());


        languagesArray.removeObject(newLanguage);
        languagesArray.insertObjectAtIndex(newLanguage,0);

        this.setLanguages(languagesArray);
  }

This almost works, but I'm having a problem... the "LogoutComponent" itself appears in the correct language, but all the sub-components it includes appear in English. I suspect this happens because they have WOHyperlinks, so a new session is created somewhere between by return pageWithName and the page actually gets sent to the browser.

Yes, that is correct. If you use an action binding on a WOHyperlink a session will be created. If this is not what you want, you will have to change the links to direct actions.



Probably, the other subcomponents are getting the language from the Session (which, at that point, i cannot control) and not from the Direct Action.

Yes.


As the session does not exist during the execution of my logoutAction() method, I cannot change it's languages array. Is there any way to solve this? Maybe forcing the creation of a session in the logoutAction() method, but I could not find out how to do it.

No, do it in changeLanguage:
public void changeLanguage(String newLanguage) {
NSMutableArray languagesArray = new NSMutableArray (this.languages());


        languagesArray.removeObject(newLanguage);
        languagesArray.insertObjectAtIndex(newLanguage,0);

        this.setLanguages(languagesArray);

session().setLanguages(languagesArray);
}


Chuck

--
Coming in 2006 - an introduction to web applications using WebObjects and Xcode http://www.global-village.net/wointro


Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems. http://www.global-village.net/products/practical_webobjects




_______________________________________________ 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
References: 
 >Logout and localization problem (From: Miguel Arroz <email@hidden>)

  • Prev by Date: Re: LDAP schema modification on OS X Server
  • Next by Date: EOGenerator/EOModeler Question
  • Previous by thread: Re: Logout and localization problem
  • Next by thread: is WOHyperlink the right answer?
  • Index(es):
    • Date
    • Thread