[opencms-dev] programatically determine which locale is currently being edited

a.westermann at alkacon.com a.westermann at alkacon.com
Wed Jul 22 12:56:38 CEST 2009


Hi Paul-Inge,

\m/(-.-)\m/


Kind Regards,
Achim.

-------------------
Achim Westermann

Alkacon Software GmbH  - The OpenCms Experts
http://www.alkacon.com - http://www.opencms.org


Gute Kunden:

Achim Westermann

-------------------

Alkacon Software GmbH - The OpenCms Experts
Achim Westermann
An der Wachsfabrik 13
50996 Koeln, DE

Tel: +49 (0)2236 3826-12
Fax: +49 (0)2236 3826-20
Email: a.westermann at alkacon.com

http://www.alkacon.com
http://www.opencms.org


Paul-Inge Flakstad wrote:
> Greetings again Marc, Achim 
> 
> I did a quick rewrite (see below) of the source code provided in the OpenCms 7 development book, and I'm glad to inform that Achim's tip did the trick. :) The select options are now being built using the editor's currently selected locale.
> 
> Many, many thanks to Achim for submitting this example code!
> 
> Best regards,
> Paul
> 
> 
>  Source changes
> ================
> 
> I_WidgetSelectSource: 
> 
> Changed 
> 	getValues(CmsObject cms) 
> to 
> 	getValues(CmsObject cms, I_CmsWidgetParameter param)
> 
> ---------------
> 
> Changed all classes implementing I_WidgetSelectSource to reflect the above change.
> 
> ---------------
> 
> CmsCustomSourceSelectWidget:
> 
> Changed 
> 	getSelectOptionData(CmsObject cms) 
> to 
> 	getSelectOptionData(CmsObject cms, I_CmsWidgetParameter param)
> 
> ---------------
> 
> ContentFieldListDS#getValues(CmsObject cms, I_CmsWidgetParameter param):
> 
> Changed the line
> 	List lVals = content.getValues(m_strFieldname, cms.getRequestContext().getLocale());
> Into this snippet
> 	// Get the editor's current locale (or fallback to default locale)
>       Locale defaultLocale = OpenCms.getLocaleManager().getDefaultLocale();
>       Locale dialogContentLocale = ((I_CmsXmlContentValue)param).getLocale();
>       Locale locale = null == dialogContentLocale ? defaultLocale : dialogContentLocale;
>       // Get the values using the specified fieldname and locale
>       List lVals = content.getValues(m_strFieldname, locale);
> 
> ---------------
> 
> That's it - hopefully I didn't forget anything. :)
> 
>> -----Original Message-----
>> From: opencms-dev-bounces at opencms.org 
>> [mailto:opencms-dev-bounces at opencms.org] On Behalf Of 
>> a.westermann at alkacon.com
>> Sent: 22. juli 2009 10:15
>> To: The OpenCms mailing list
>> Subject: Re: [opencms-dev] programatically determine which 
>> locale is currently being edited
>>
>> Hi Marc,
>>
>> I think it is this dirty and hidden (the cast!) trick:
>>
>>      protected List parseSelectOptions(CmsObject cms, 
>> I_CmsWidgetDialog 
>> widgetDialog, I_CmsWidgetParameter param)
>>      throws CmsIllegalArgumentException {
>>
>>          Locale dialogContentLocale = 
>> ((I_CmsXmlContentValue)param).getLocale();
>> ...
>> }
>>
>>
>> Use it wherever you need it and have an I_CmsWidgetParameter argument.
>>
>>
>> Kind Regards,
>> Achim.
>>
>> -------------------
>> Achim Westermann
>>
>> Alkacon Software GmbH  - The OpenCms Experts
>> http://www.alkacon.com - http://www.opencms.org
>>
>>
>>
>>
>> Marc.Schlegel wrote:
>>> Hello Everyone
>>>
>>> After solving my problem with the CustomSelectWidget (the 
>> one from the
>>> OpenCms 7 book), there is one more tiny (but important) 
>> detail that I
>>> need to solve.
>>>
>>> First I have to thank Paul for helping me previously and he whas
>>> actually also the one phrasing this question.
>>>
>>> The point is, how can we get the correct Locale that is 
>> currently being
>>> edited in a structured content editor. As some of you might 
>> remember,
>>> the CustomWidget in the book is reading the possible values 
>> from another
>>> structured content. This one of course can have several languages as
>>> well. So when I switch the language in the editor that uses this
>>> CustomWidget, the widget should change its contents to the 
>> corresponding
>>> language as well.
>>>
>>> So, as the subject says: how to programatically determine 
>> which locale
>>> is currently being edited? And how to refresh the widget 
>> when the editor
>>> changes the language?
>>>
>>> Thanks in advance
>>> Marc
>>>
>>> _______________________________________________
>>> This mail is sent to you from the opencms-dev mailing list
>>> To change your list options, or to unsubscribe from the 
>> list, please visit
>>> http://lists.opencms.org/mailman/listinfo/opencms-dev
>> _______________________________________________
>> This mail is sent to you from the opencms-dev mailing list
>> To change your list options, or to unsubscribe from the list, 
>> please visit
>> http://lists.opencms.org/mailman/listinfo/opencms-dev
>>
> 
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/mailman/listinfo/opencms-dev



More information about the opencms-dev mailing list