我需要檢查我的portlet是否有用戶選擇作爲其「主要」語言的語言,爲此,我必須先獲取UserID(名稱)。我一直在尋找它兩天(Liferay論壇,vaadin論壇,stackoverflow等),但沒有發現,將工作到目前爲止。使用Vaadin獲取Liferay用戶信息
我找到了一個很好的例子,但它似乎並沒有工作(它總是返回「null」)。
package com.example.translation_portlet;
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.User;
import com.liferay.portal.util.PortalUtil;
import com.vaadin.Application;
import com.vaadin.terminal.gwt.server.PortletRequestListener;
import com.vaadin.ui.Label;
import com.vaadin.ui.Window;
public class Translation_portletApplication extends Application implements
PortletRequestListener {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public void init() {
Window mainWindow = new Window("LoginApplication");
Label label = new Label("Hello anonymous Vaadin user");
if (getUser() != null) {
// user has logged in
label = new Label("Hello " + ((User) getUser()).getFullName());
}
mainWindow.addComponent(label);
setMainWindow(mainWindow);
}
@Override
public void onRequestStart(PortletRequest request, PortletResponse response) {
if (getUser() == null) {
try {
User user = PortalUtil.getUser(request);
setUser(user);
} catch (PortalException e) {
e.printStackTrace();
} catch (SystemException e) {
e.printStackTrace();
}
}
}
@Override
public void onRequestEnd(PortletRequest request, PortletResponse response) {
// Nothing to do here currently, exists only to implement the
// PortletRequestListener interface.
}
}
編輯:
這是我迄今tryed:
locale = user.getLocale();
button.setCaption(LanguageUtil.get(locale, "first_name"));
,並在我的Language.properties我有翻譯爲 「FIRST_NAME」 設置爲第一名稱:
first_name=1st Name
Language.properties文件位於我已添加的內容文件夾中,並且資源包我的portlet.xml太:
<resource-bundle>content/Language</resource-bundle>
按鈕的標題設置爲「FIRST_NAME」不是第一個名字,如果我改變的關鍵是直呼其名我從language.properties得到一個默認的轉換沒有我tranlsation文件,我錯過了什麼?
LanguageUtil將從liferay屬性文件中獲取屬性。我會編輯答案。 –