Foren

Localization and HttpServletRequest

thumbnail
hadi terkawi, geändert vor 16 Jahren.

Localization and HttpServletRequest

New Member Beiträge: 6 Beitrittsdatum: 04.11.07 Neueste Beiträge
Hi All:
I am trying to make a localized JSF portlet using Sun Studio Creator.
I have tried Sun Creator tutorial:
http://developers.sun.com/jscreator/learning/tutorials/2/demonstrating_i18n.html
and It works fine on both sun server and liferay.
The only thing I need to know is how to get the curent Locale of liferay in order to change my portlet locale with it.
I searched the web and find that the way to find the locale of the page is by using HttpServletRequest object (getLocale) property.
I have tried code that appears like this:

ExternalContext econtext = getExternalContext();
javax.servlet.http.HttpServletRequest request = (javax.servlet.http.HttpServletRequest )
econtext.getRequest();
Locale locale = new Locale("En_US");
locale =request.getLocale();

This works fine on Sun Plato Server but on Tomcat (Liferay) I have got an error which is ClassCastException.
I have searched liferay for such problem and find this:
http://www.liferay.com/web/guest/community/forums/message_boards/message/388738?_19_redirect=%2Fweb%2Fguest%2Fcommunity%2Fforums%3Fp_p_id%3D19%26p_p_action%3D0%26p_p_state%3Dmaximized%26p_p_mode%3Dview%26_19_struts_action%3D%252Fmessage_boards%252Fsearch%26_19_redirect%3D%252Fweb%252Fguest%252Fcommunity%252Fforums%252Fmessage_boards%26_19_breadcrumbsCategoryId%3D0%26_19_searchCategoryIds%3D0%26_19_keywords%3Dhttpservletrequest&

which summary is that liferay does not offer an access to the httpServletRequest and liferay offers PortletRequest object is supposed to give everything needed but this object doesn't have anything about the locale.

Anyone have a way to get the current liferay locale from my portlet.