-
1. Re: HOW to change Locale in Program?
theute Mar 20, 2007 4:37 AM (in response to qqqqzaza)The common way in a portal is to use the user profile.
-
2. Re: HOW to change Locale in Program?
qqqqzaza Mar 20, 2007 5:41 AM (in response to qqqqzaza)I know we can change locale using User Profile setting.
But in my case, i wanna build a project that contains a header with links to swap language of the whole pages. (my project uses struts to handle action )
is there any other methods to deal with this ?
thx -
3. Re: HOW to change Locale in Program?
theute Mar 20, 2007 5:58 AM (in response to qqqqzaza)So you want non-logged in user to be able to change the locale as well ?
For logged-in user you should change the preference (you don't have to do it using the portlet, nothing prevent you from creating your own action calling the identity service to update the preferred language)
For non-logged-in user, you would have to define how you want to store the preferred locale (session probably) and adapt org.jboss.portal.core.aspects.server/LocaleInterceptor accordingly -
4. Re: HOW to change Locale in Program?
qqqqzaza Mar 21, 2007 5:23 AM (in response to qqqqzaza)Thx for your reply.
But could you tell me how to adapt or change the class LocaleInterceptor?
(if i want to store it in session)
Thx -
5. Re: HOW to change Locale in Program?
qqqqzaza Mar 21, 2007 11:36 PM (in response to qqqqzaza)i have changed LocaleInterceptor.java..
there is another struts ChangeLocale program which will set locale to session
but it seems not work....help..
public class LocaleInterceptor extends ServerInterceptor
{
/** The logger. */
protected Logger log = Logger.getLogger(getClass());
protected void invoke(ServerInvocation invocation) throws Exception, InvocationException
{
ServerRequest req = invocation.getRequest();
// Locale locale = req.getContext().getClientRequest().getLocale();
HttpSession session = req.getContext().getClientRequest().getSession();
Locale locale = (Locale) session.getAttribute"org.apache.struts.action.LOCALE");
log.debug("LocaleInterceptor Locale: "+locale);
if (locale == null){
locale = req.getContext().getClientRequest().getLocale();
log.debug("2. LocaleInterceptor Locale: "+locale);
session.setAttribute("org.apache.struts.action.LOCALE", locale);
}
try
{
req.setLocales(new Locale[]{locale});
invocation.invokeNext();
}
finally
{
req.setLocales(null);
}
}
} -
6. Re: HOW to change Locale in Program?
jvence Feb 22, 2008 2:16 PM (in response to qqqqzaza)"qqqqzaza" wrote:
Thx for your reply.
But could you tell me how to adapt or change the class LocaleInterceptor?
(if i want to store it in session)
Thx
Did you ever to get this working? Thanks -
7. Re: HOW to change Locale in Program?
littleprince Feb 23, 2008 4:44 AM (in response to qqqqzaza)I m facing the same problem. I have the difficulties of getting the session at portlet or LocaleInterceptor from httpSession.
i set the value at attribute of a servletpublic void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try{ req.getSession().setAttribute("value", "value1"); resp.sendRedirect(""); }catch(Exception e){} }
and i try to get the value from portlet by the code below and it fails to get the value also.rRequest.getPortletSession(true).getAttribute("value", PortletSession.APPLICATION_SCOPE))
or at LocaleInterceptor, the below line also gave me error.req.getContext().getClientRequest().getSession();
Anyone can advise me on this?
Thanks in advance.