close
Liferay的tag<liferay-ui:input-localized name="" xml="" type=""/>可以用來做多國語言的輸入textbox或是富文本編輯器。
其中type="editor"便可以將text轉換成編輯器的模式,但是是簡易版的編輯器,若是使用hook可以將這個編輯器改成標準版編輯器,但是尚未確定是否會有任何問題。
一般custom portlet的使用方式:
Service.xml要先設定我們要用來存放多國語言資料的欄位,例如:
<column name="description" type="String" localized="true"/>
其中localized設定為true,Liferay便會幫我們建置一些方法用來存多國語言的map以及xml資料。Build Service之後會有如下方法:
model.setDescriptionMap("map");
model.getDescription(themeDisplay.getLocale())
此方法用來存以及根據語系取得多國語言textbox所傳的值,而數值的接收用法如下:
Map<Locale, String> translations = LocalizationUtil.getLocalizationMap(request, "description");
接收的map長得像這樣:{en_US=A, zh_TW=B}
這時候liferay-ui:input-localized tag就可以設定xml為model.getdescription(),會直接以xml形式讀取。
input介面如下所示:
DB內所存的資料如下所示:
結合configuration的使用方式;
configuration.jsp:
<aui:form action="<%=configurationURL%>" method="post">
<aui:input name="<%= Constants.CMD %>" type="hidden" value="<%=Constants.UPDATE %>" />
<font style="font-size:14px;"><liferay-ui:message key="main-description:" /></font><br>
<liferay-ui:input-localized name="mainDescription" xml="<%=mainDescriptionXml %>" style="width:400px;" type="editor_custom"/>
<aui:button type="submit" icon="icon-ok-sign" />
</aui:form>
init.jsp:
//取得首頁歡迎文字,來自於configuration,這裡跟一般取值時用的方法不太一樣,是用LocalizationUtil來取得資料
String mainDescriptionXml = LocalizationUtil.
getLocalizationXmlFromPreferences(portletPreferences, renderRequest, "mainDescription");
Map<Locale, String> mainDescriptionMap = LocalizationUtil.getLocalizationMap(mainDescriptionXml, false);
String mainDescription = mainDescriptionMap.get(themeDisplay.getLocale());
ConfigurationActionImpl.java:
public void processAction(PortletConfig portletConfig,
ActionRequest actionRequest, ActionResponse actionResponse)
throws Exception {
String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
if (cmd.equals(Constants.UPDATE)) {
PortletPreferences preferences = actionRequest.getPreferences();
//用 LocalizationUtil.setLocalizedPreferencesValues去存值。
LocalizationUtil.setLocalizedPreferencesValues(actionRequest, preferences, "mainDescription");
preferences.store();
}
super.processAction(portletConfig, actionRequest, actionResponse);
}
|
完成畫面:


全站熱搜