<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>[SOLVED] aui localized form: how to write/read localized content?</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=110905719" />
  <subtitle>[SOLVED] aui localized form: how to write/read localized content?</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=110905719</id>
  <updated>2026-04-03T21:07:14Z</updated>
  <dc:date>2026-04-03T21:07:14Z</dc:date>
  <entry>
    <title>RE: aui localized form: how to write/read localized content?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110914054" />
    <author>
      <name>Mirto Silvio Busico</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110914054</id>
    <updated>2018-09-10T09:32:45Z</updated>
    <published>2018-09-10T09:32:45Z</published>
    <summary type="html">&lt;p&gt;Solved. With this code I can use an aui:form to read/write localized content.&lt;/p&gt;
&lt;p&gt;In&lt;strong&gt; service.xml&lt;/strong&gt; I have&lt;/p&gt;
&lt;pre&gt;
        &amp;lt;column name=&amp;quot;field1&amp;quot; type=&amp;quot;String&amp;quot; localized=&amp;quot;true&amp;quot; /&amp;gt;
&lt;/pre&gt;
&lt;p&gt;In &lt;strong&gt;edit_foo.jsp&lt;/strong&gt; I have&lt;/p&gt;
&lt;pre&gt;
&amp;lt;aui:form
    action=&amp;quot;&amp;lt;%= (javax.portlet.ActionURL)renderResponse.createActionURL() %&amp;gt;&amp;quot;
    name=&amp;quot;fm1&amp;quot;
&amp;gt;
   
[snip]
    &amp;lt;aui:fieldset&amp;gt;
        &amp;lt;aui:input name=&amp;quot;field1&amp;quot; localized=&amp;quot;&amp;lt;%= true %&amp;gt;&amp;quot; /&amp;gt;

[snip]&lt;/pre&gt;
&lt;p&gt;In &lt;strong&gt;MsbOnePortlet.java&lt;/strong&gt; I have&lt;/p&gt;
&lt;pre&gt;
[snip]    
protected void updateFoo(ActionRequest actionRequest) throws Exception {
        long fooId = ParamUtil.getLong(actionRequest, &amp;quot;fooId&amp;quot;);

[snip]        
        Set&amp;lt;Locale&amp;gt; locales = LanguageUtil.getAvailableLocales();

        Map&amp;lt;Locale, String&amp;gt; field1Map = new HashMap&amp;lt;Locale, String&amp;gt;();
        for (Locale locale : locales) {
            String languageId = LocaleUtil.toLanguageId(locale);
            String x1 = &amp;quot;field1&amp;quot;;
            String localeParameter = x1.concat(StringPool.UNDERLINE).concat(languageId);
            String y1 = ParamUtil.getString(actionRequest,localeParameter);
            field1Map.put(locale, y1);
        }
[snip]            
        &lt;strong&gt;foo.setField1Map(field1Map);&lt;/strong&gt;
&lt;/pre&gt;
&lt;p&gt;This create the field1 content:&lt;/p&gt;
&lt;pre&gt;
&amp;lt;?xml version='1.0' encoding='UTF-8'?&amp;gt;
&amp;lt;root available-locales=&amp;quot;en_US,it_IT,&amp;quot; default-locale=&amp;quot;en_US&amp;quot;&amp;gt;
&amp;lt;Field1 language-id=&amp;quot;en_US&amp;quot;&amp;gt;f1 english&amp;lt;/Field1&amp;gt;
&amp;lt;Field1 language-id=&amp;quot;it_IT&amp;quot;&amp;gt;f1 italiano&amp;lt;/Field1&amp;gt;
&amp;lt;/root&amp;gt;
&lt;/pre&gt;
&lt;p&gt;This content is correctly interpretaded by aui:form which show the
  field content in all translated languages&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;</summary>
    <dc:creator>Mirto Silvio Busico</dc:creator>
    <dc:date>2018-09-10T09:32:45Z</dc:date>
  </entry>
  <entry>
    <title>[SOLVED] aui localized form: how to write/read localized content?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110905718" />
    <author>
      <name>Mirto Silvio Busico</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110905718</id>
    <updated>2018-09-07T11:32:29Z</updated>
    <published>2018-09-07T11:32:29Z</published>
    <summary type="html">&lt;p&gt;Hi all,&lt;/p&gt;
&lt;p&gt;I'm trying to develop an MVC portlet that manages localized content
  using &lt;strong&gt;Liferay 7.1 CE GA 1&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;After many attempts (and many thread in this forum) I ended up with
  half solution: I'm able to use an &lt;strong&gt;aui:form&lt;/strong&gt; to acquire
  localized content; but I cannot save the data in any form that is
  recognized by aui.&lt;/p&gt;
&lt;p&gt;I mean:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;in the browser in a field (field1) I enter english and italian translation&lt;/li&gt;
  &lt;li&gt;debugging the portlet for edit action I can see that
    the english and italian translation are there&lt;/li&gt;
  &lt;li&gt;I store the field as a map &amp;lt;Locale,String&amp;gt; converted to string&lt;/li&gt;
  &lt;li&gt;when I try to edit the record, the field1 content is the  strored
    string assigned to the default language and the translation is lost&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;How can I write and read localized content so that
  &lt;strong&gt;aui:form&lt;/strong&gt; is happy and show all translations?&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;h1&gt;
  &lt;strong&gt;TL;DR&lt;/strong&gt;&lt;/h1&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;This is what I have and what I attempted.&lt;/p&gt;
&lt;p&gt;In&lt;strong&gt; service.xml&lt;/strong&gt; I have&lt;/p&gt;
&lt;pre&gt;
        &amp;lt;column name=&amp;quot;field1&amp;quot; type=&amp;quot;String&amp;quot; localized=&amp;quot;true&amp;quot; /&amp;gt;
&lt;/pre&gt;
&lt;p&gt;In &lt;strong&gt;edit_foo.jsp&lt;/strong&gt; I have&lt;/p&gt;
&lt;pre&gt;
&amp;lt;aui:form
    action=&amp;quot;&amp;lt;%= (javax.portlet.ActionURL)renderResponse.createActionURL() %&amp;gt;&amp;quot;
    name=&amp;quot;fm1&amp;quot;
&amp;gt;
   
[snip]
    &amp;lt;aui:fieldset&amp;gt;
        &amp;lt;aui:input name=&amp;quot;field1&amp;quot; localized=&amp;quot;&amp;lt;%= true %&amp;gt;&amp;quot; /&amp;gt;

[snip]&lt;/pre&gt;
&lt;p&gt;In the browser I typed two translation - &lt;strong&gt;see aui-field1.png attachment&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;You can see that en_US is the default language and that it_IT is
  translated (BTW when it_IT is selected under the input field the en_US
  translation is showed)&lt;/p&gt;
&lt;p&gt;In &lt;strong&gt;MsbOnePortlet.java&lt;/strong&gt; I have&lt;/p&gt;
&lt;pre&gt;
[snip]

    protected void updateFoo(ActionRequest actionRequest) throws Exception {
        long fooId = ParamUtil.getLong(actionRequest, &amp;quot;fooId&amp;quot;);

        boolean field2 = ParamUtil.getBoolean(actionRequest, &amp;quot;field2&amp;quot;);
        int field3 = ParamUtil.getInteger(actionRequest, &amp;quot;field3&amp;quot;);
        
        Set&amp;lt;Locale&amp;gt; locales = LanguageUtil.getAvailableLocales();

        Map&amp;lt;Locale, String&amp;gt; map1 = new HashMap&amp;lt;Locale, String&amp;gt;();
        for (Locale locale : locales) {
            String languageId = LocaleUtil.toLanguageId(locale);
            String x1 = &amp;quot;field1&amp;quot;;
            String localeParameter = x1.concat(StringPool.UNDERLINE).concat(languageId);
            String y1 = ParamUtil.getString(actionRequest,localeParameter);
            map1.put(locale, y1);
        }        
        &lt;strong&gt;String field1 = map1.toString();&lt;/strong&gt;
        System.out.println(&amp;quot;mappato field1&amp;quot;);
[snip]        
&lt;/pre&gt;
&lt;p&gt;Debugging this code I see that field1 contains&lt;/p&gt;
&lt;pre&gt;
{es_ES=, it_IT=Campo 1 testo in italiano, fr_FR=, en_US=Field 1 english text, de_DE=}
&lt;/pre&gt;
&lt;p&gt;See the &lt;strong&gt;map and the field in the debug-field1.png&lt;/strong&gt; attachment&lt;/p&gt;
&lt;p&gt;When I try to edit the the row, the edit_foo.jsp page shows the
  string as the default language translation and that there is no
  italian translation. See&lt;strong&gt; aui-field1-edit.png&lt;/strong&gt; attachment&lt;/p&gt;
&lt;p&gt;I tried also to see how the journal article was developed but I lost
  myself in the code (&lt;a href="https://github.com/liferay/liferay-portal/tree/master/modules/apps/journal"&gt;https://github.com/liferay/liferay-portal/tree/master/modules/apps/journal&lt;/a&gt; )&lt;/p&gt;
&lt;p&gt;What I have to do?&lt;/p&gt;</summary>
    <dc:creator>Mirto Silvio Busico</dc:creator>
    <dc:date>2018-09-07T11:32:29Z</dc:date>
  </entry>
</feed>
