You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by gcormier <ma...@tapestryforums.com> on 2006/02/02 15:48:14 UTC

How to switch locales?

Okay, I've read up in the Tapestry book about switching locales. They don't quite do it the way I want to.

Basically, at the top of my page, if you're browsing in engilsh, you'll have a "French" link. If you're browsing in French, there will be an "English" link instead.

Right now, I have an @DirectLink, with "listeners:toggleLocale". This is what's inside :

public void toggleLocale(IRequestCycle cycle)
	{
		((BorderEngine) getPage().getEngine()).toggleLocale();
		cycle.activate("Welcome");
	}

My Engine, which I've over-rode, is

	public void toggleLocale()
	{
		if (getLocale() == Locale.ENGLISH)
			setLocale(Locale.FRENCH);
		else
			setLocale(Locale.ENGLISH);
	}


Now, this seems to be working. However, there's the famous problem mentioned that you need to get a new page once you switch the Locale. So my question is... how? This French/English link is available on every page, and should return them to the page they came from.

Thanks,
Greg


-------------------- m2f --------------------

Sent from www.TapestryForums.com

Read this topic online here: <<topic_link>>

http://www.tapestryforums.com/viewtopic.php?p=14238#14238

-------------------- m2f --------------------



Re: How to switch locales?

Posted by Geoff Longman <gl...@gmail.com>.
In a component you can throw a redirect just by asking it for the page
it's embedded in.

public void toggleLocale(IRequestCycle cycle)
{
   ((BorderEngine) getPage().getEngine()).toggleLocale();
   cycle.cleanup();
   throw new PageRedirectException(getPage());
}

Geoff



On 2/3/06, gcormier <ma...@tapestryforums.com> wrote:
> Thanks.
>
> Unfortunately I can't use  throw new PageRedirectException(this); because I'm using a Border component. So the border has this common french/english link as well as other menu items.
>
> Would that callback still work?
>
> Thanks,
> Greg
>
>
> -------------------- m2f --------------------
>
> Sent from www.TapestryForums.com
>
> Read this topic online here: <<topic_link>>
>
> http://www.tapestryforums.com/viewtopic.php?p=14297#14297
>
> -------------------- m2f --------------------
>
>
>
>


--
The Spindle guy.          http://spindle.sf.net
Get help with Spindle:   
http://lists.sourceforge.net/mailman/listinfo/spindle-user
Blog:                     http://jroller.com/page/glongman
Feature Updates:          http://spindle.sf.net/updates

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: How to switch locales?

Posted by Ron Piterman <rp...@gmx.net>.
you can still throw the exception, instead of "this" use "getPage()"
cheers,
Ron


gcormier wrote:
> Thanks.
> 
> Unfortunately I can't use  throw new PageRedirectException(this); because I'm using a Border component. So the border has this common french/english link as well as other menu items.
> 
> Would that callback still work?
> 
> Thanks,
> Greg
> 
> 
> -------------------- m2f --------------------
> 
> Sent from www.TapestryForums.com
> 
> Read this topic online here: <<topic_link>>
> 
> http://www.tapestryforums.com/viewtopic.php?p=14297#14297
> 
> -------------------- m2f --------------------
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


RE: How to switch locales?

Posted by gcormier <ma...@tapestryforums.com>.
Thanks.

Unfortunately I can't use  throw new PageRedirectException(this); because I'm using a Border component. So the border has this common french/english link as well as other menu items.

Would that callback still work?

Thanks,
Greg


-------------------- m2f --------------------

Sent from www.TapestryForums.com

Read this topic online here: <<topic_link>>

http://www.tapestryforums.com/viewtopic.php?p=14297#14297

-------------------- m2f --------------------



RE: How to switch locales?

Posted by gcormier <ma...@tapestryforums.com>.
:) Nice! It worked! This is awesome!!! Thank you both :)

Greg


-------------------- m2f --------------------

Sent from www.TapestryForums.com

Read this topic online here: <<topic_link>>

http://www.tapestryforums.com/viewtopic.php?p=14308#14308

-------------------- m2f --------------------



Re: How to switch locales?

Posted by Mind Bridge <mi...@yahoo.com>.
Hi,

Could you try the following:

public void toggleLocale(IRequestCycle cycle)
{
    ((BorderEngine) getPage().getEngine()).toggleLocale();
    cycle.cleanup();
    throw new PageRedirectException(this);
}

Another option in case you want an intermediate page is to use a 
callback -- please look at the classes in org.apache.tapestry.callback.

Best regards,
-mb

gcormier wrote:
> Okay, I've read up in the Tapestry book about switching locales. They don't quite do it the way I want to.
>
> Basically, at the top of my page, if you're browsing in engilsh, you'll have a "French" link. If you're browsing in French, there will be an "English" link instead.
>
> Right now, I have an @DirectLink, with "listeners:toggleLocale". This is what's inside :
>
> public void toggleLocale(IRequestCycle cycle)
> 	{
> 		((BorderEngine) getPage().getEngine()).toggleLocale();
> 		cycle.activate("Welcome");
> 	}
>
> My Engine, which I've over-rode, is
>
> 	public void toggleLocale()
> 	{
> 		if (getLocale() == Locale.ENGLISH)
> 			setLocale(Locale.FRENCH);
> 		else
> 			setLocale(Locale.ENGLISH);
> 	}
>
>
> Now, this seems to be working. However, there's the famous problem mentioned that you need to get a new page once you switch the Locale. So my question is... how? This French/English link is available on every page, and should return them to the page they came from.
>
> Thanks,
> Greg
>
>
> -------------------- m2f --------------------
>
> Sent from www.TapestryForums.com
>
> Read this topic online here: <<topic_link>>
>
> http://www.tapestryforums.com/viewtopic.php?p=14238#14238
>
> -------------------- m2f --------------------
>
>
>
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org