I wrote a portlet for Liferay in Java, Jquery and Javascript.
I am trying to get the language of the userprofil that is using my portlet.
I already got the uuid and can use it.
If i try to get the language the same way i receive null.
My JavaClass:
public class UserId extends MVCPortlet {
public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException {
ThemeDisplay td =(ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
User user = td.getUser();
/*String userLanguage = td.getLocale().toString();*/
/*String userLanguage = user.getLanguageId();*/
String userLanguage = LanguageUtil.getLanguageId(renderRequest);
String userId = user.getUuid();
renderRequest.setAttribute("myUser", userId);
renderRequest.setAttribute("myUserLang", userLanguage);
super.doView(renderRequest, renderResponse);
}
}
As you can see i tried to get userLanguage with three different methods.
My View.jsp:
<portlet:defineObjects />
<%
String userIdIntern = renderRequest.getRemoteUser();
String userIdExtern = (String) request.getAttribute("myUser");
String userLang = (String) request.getAttribute("myUserLang");
%>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
userId = "<%=userIdExtern%>";
debug(userId);
var testLang = "<%=userLang%>";
debug("testLang obj: "+testLang); // returns null
});
/* more code below */
If i use td.getLocale() i at least get an object instead of null. Using .toString() returns null again.
How can i get the currently used language for an userprofile?