You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Markus Reinhardt <mr...@hygiene.uni-wuerzburg.de> on 2006/06/26 09:36:32 UTC

MessageTool, change locale

Hi,

I am using the struts-utils MessageTool in combination with struts and
am experiencing certain problems.

I have an action to switch the locale to a specified value which
executes the following code:


session.setAttribute(Globals.LOCALE_KEY, locale);


Where locale is choosen via HTTP request. This action works as intended
which means after execution
$request.session.getAttribute('org.apache.struts.action.LOCALE') returns
the correct locale (en or de in my case) and the page is displayed in
the chosen language.

But in some cases, I guess it happens if someone with default locale
'en' accesses my website everything gets mixed up.

Where the above action still works as mentioned above, the whole page
stays german for EVERY request (even with different session) until I
restart it via the tomcat manager.

I took a look in org.apache.velocity.tools.struts.StrutsUtils
getLocale(..) method:


public static Locale getLocale(HttpServletRequest request, HttpSession session)
{
  Locale locale = null;
  if (session != null)
  {
    locale = (Locale)session.getAttribute(Globals.LOCALE_KEY);
  }
  if (locale == null)
  {
    locale = request.getLocale();
  }
  return locale;
}


The MessageTool resides in request scope, which means this method should
return the session key. At least after my action was executed and a new
session created:


HttpSession session = request.getSession();


I really don't see the point where I did something wrong. Btw.
request.getLocale() always returns 'de' (even if the problem doesn't
appear). This at least explains why everything is german after the
error.

Any help would be greatly appreciated,

Markus


Re: AJAX and Velocity - Any experience ?

Posted by Will Glass-Husain <wg...@forio.com>.
Yes.

Nothing special about Velocity and AJAX, except that it is easy to 
create AJAX responses via tiny Velocity files.  These responses could be 
XML, JSON, or a Javascript callback function.

Another AJAX technique I've used succesfully recently is to populate a 
div tag with text that's updated periodically in the background (without 
refreshing the whole page).  The prototype.js library has a nice 
function for this: Ajax.Updater.  Again, Velocity makes it easy to craft 
the response (in this case, the HTML that is loaded into the div tag).

WILL

Steve O'Hara wrote:
> Hi,
>  
> I'm starting to get interested in AJAX with my Velocity apps and
> wondered if anyone in the Velocity community has had any experiences
> with it.  It seems like a good marriage of technologies (AJAX isn't
> really a 'technology' of course but more of a methodology)
>  
> Thanks,
>  
> Steve
>
>   

-- 
Forio Business Simulations

Will Glass-Husain
phone (415) 440-7500 x89
mobile (415) 235-4293
wglass@forio.com
www.forio.com


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


AJAX and Velocity - Any experience ?

Posted by Steve O'Hara <so...@pivotal-solutions.co.uk>.
Hi,
 
I'm starting to get interested in AJAX with my Velocity apps and
wondered if anyone in the Velocity community has had any experiences
with it.  It seems like a good marriage of technologies (AJAX isn't
really a 'technology' of course but more of a methodology)
 
Thanks,
 
Steve