Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
AUI:FORM do not switch correctly locale
Mirto Silvio Busico, modified 7 Years ago.
Regular Member
Posts: 240
Join Date: 1/18/12
Recent Posts
Hi all,
I'm trying to develop a localized MVC portlet in Liferay 7.1
I'm able to read/write localized content but the form show the instance default language instead of the current selected language.
Looking at the eng-ita.png screenshot you can see that the language selected (using the language selector portlet) is en_US; but the form fields are shown in it_IT
The form header that is set using:
String currentLanguageId = LocaleUtil.toLanguageId(user.getLocale()); title='<%= (foo != null) ? foo.getField1(currentLanguageId) : "new-foo" %>'
shows correctly the english version.
What can I do to show the current language in aui:form?
TL;DR
The complete code for the edit_foo.jsp file
<%@ include file="/init.jsp" %>
<%
String currentLanguageId = LocaleUtil.toLanguageId(user.getLocale());
String redirect = ParamUtil.getString(request, "redirect");
long fooId = ParamUtil.getLong(request, "fooId");
Foo foo = null;
if (fooId > 0) {
foo = fooLocalService.getFoo(fooId);
}
%>
<aui:form
action="<%= (javax.portlet.ActionURL)renderResponse.createActionURL() %>"
name="fm1"
>
<aui:input name="<%= Constants.CMD %>" type="hidden" value="<%= (foo == null) ? Constants.ADD : Constants.UPDATE %>" />
<aui:input name="redirect" type="hidden" value="<%= currentURL %>" />
<aui:input name="fooId" type="hidden" value="<%= fooId %>" />
<liferay-ui:header
backURL="<%= redirect %>"
title='<%= (foo != null) ? foo.getField1(currentLanguageId) : "new-foo" %>'
/>
<liferay-ui:asset-categories-error />
<liferay-ui:asset-tags-error />
<aui:model-context bean="<%= foo %>" model="<%= Foo.class %>" />
<aui:fieldset>
<aui:input name="field1" localized="<%= true %>" />
<aui:input name="field2" />
<aui:input name="field3" />
<aui:input name="field4" />
<aui:input name="field5" localized="<%= true %>"/>
<aui:input name="field6" localized="<%= true %>"/>
<liferay-ui:custom-attributes-available className="<%= Foo.class.getName() %>">
<liferay-ui:custom-attribute-list
className="<%= Foo.class.getName() %>"
classPK="<%= (foo != null) ? foo.getFooId() : 0 %>"
editable="<%= true %>"
label="<%= true %>"
/>
</liferay-ui:custom-attributes-available>
<aui:input name="categories" type="assetCategories" />
<aui:input name="tags" type="assetTags" />
</aui:fieldset>
<aui:button-row>
<aui:button type="submit" />
<aui:button href="<%= redirect %>" type="cancel" />
</aui:button-row>
</aui:form>
Attachments: