File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes switching language on the fly with struts Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Application Frameworks » Struts
Reply Bookmark "switching language on the fly with struts" Watch "switching language on the fly with struts" New topic
Author

switching language on the fly with struts

Julie Richard
Greenhorn

Joined: Sep 27, 2004
Posts: 3
Hiyas,

I need to give users the possibility to switch language on the fly.

What has been done so far is go through a struts action, save the newly preferred language for the user (in db), put the new value in the session variable (Action.LOCALE_KEY), then forward back to the home page.

Everything works fine exept 1 thing, if we access a page in a certain language and then switch language (forwarded to home) and go back to the page, it is still in the previous language (because it was 'cached by the browser I think).

I have added the meta tags for expiration, but it seems to still be the problem (those darn tags..).

So far, the only way to fix it would be to set the browser's cache settings to 'every visit to page', so it would be reloaded all the time (this actually works pretty well.. but I can't ask users to change their settings like that..)

Another thing (bonus!! ), how do you guys give the possibility to switch language while keeping the user on the same page? The only way I can think of is to check the request URL in the action.. and then go through some kind of mapping mechanism (that associates pages url with struts action), then try to forward to the action that had forwarded to that page in the first place.

anyways.. I sure hope someone can help me with that.. been stumbling around with that for a couple days..

Free kisses to anyone who can help me with this one..
First time I post here.. but I've been watching you for a long time now...

TIA!!

Ju
Julie Richard
Greenhorn

Joined: Sep 27, 2004
Posts: 3
anyone?

come on you mooses, you can do it!!
Julie Richard
Greenhorn

Joined: Sep 27, 2004
Posts: 3
ok.. I've fixed one of my problems.. not much interest in it by other mooses.. but I'll still post it here in case it helps others..

If you remember in yesterday's episode,
I had problems with the

<meta http-equiv="expires" content="Wed, 03 Nov 1999 12:21:14 GMT">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" Content="no-cache">

tags that would not tell IE to not cache my pages (so when switching language, it would still display with the previous one unless we forced refresh). I've tried them all with no luck...

That being said.. if you add another <head> tag at the end of your page, like this :

<html>
<head>
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
....
</head>
<body>...</body>
<HEAD><META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"></HEAD>
</html>

it will be handled correctly by IE and will not cache the page..


this is crazy.. but it actually works...

anyone sees problem with this quick and dirty fix?
anyone has anything else to share?

thanks.. well.. for your support if not for your help..
Marek Lapin
Greenhorn

Joined: Sep 19, 2004
Posts: 15
Well, i don't know about LOCALE_KEY, but if you use message resources to display internationalized text and set the local variable in the session
(Action.setLocale(...)) to desired language, then all the correct message resources should be displayed (according to the new locale session variable)
sreenath reddy
Ranch Hand

Joined: Sep 21, 2003
Posts: 415
Hi richard

For ur kind info its not only the matter of caching anf if u r using the struts1.1 the locale will be stored in the session with key named Globals.LOCALE_KEY .it used to be in 1.0 that it was stored in Action.LOCALE_KEY........

after setting ur new value to this will make ur language switching
 
 
subject: switching language on the fly with struts
 
Threads others viewed
Successive forwards
Struts-Forward back to original page
Struts 1 - Using ActionForm in the response
history.back() in Netscape 7.2
How to call a .do directly?
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture