Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6855047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:42:31+00:00 2026-05-27T01:42:31+00:00

I need to check in my portlet wich language does an user have selected

  • 0

I need to check in my portlet wich language does an user have selected as his “main” language, to do that, I have to get the UserID (name) first . i have been looking for it for two days (Liferay forums , vaadin forums , stackoverflow etc.) but nothing found that would work so far.

I have found an nice example but it doesnt seem to work (It always returns “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.
    }

}

EDIT :

this is what i have tryed so far :

locale = user.getLocale();
button.setCaption(LanguageUtil.get(locale, "first_name"));

and in my Language.properties i have the translation for “first_name” set to 1st Name:

first_name=1st Name

the Language.properties file is located in my content folder i have added and resource-bundle to my portlet.xml too :

    <resource-bundle>content/Language</resource-bundle>

The caption of the button is set to “first_name” not 1st name , if i change the key to first-name i get an default translation no my tranlsation from the language.properties file , am i missing something ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:42:31+00:00Added an answer on May 27, 2026 at 1:42 am

    Did you try with

    final ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKey.THEME_DISPLAY);
    themeDisplay.getUser().getLanguageId();
    

    Imports needed are

    import javax.portlet.PortletRequest;
    import com.liferay.portal.kernel.util.WebKeys;
    import com.liferay.portal.theme.ThemeDisplay;
    

    EDIT:

    Try with this

       @Override
    public void onRequestStart(PortletRequest request, PortletResponse response) {
    
                final ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKey.THEME_DISPLAY);
                final User user = themeDisplay.getUser();
    
                if (user != null) {
                    // will be printed to log/console
                    System.out.println("User's language id = " + user.getLanguageId());
                } else {
                    System.out.println("Guest user.");
                }
    
                setUser(user);
    }
    

    You can also try

    @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() + ", language id is '" + user.getLanguageId() + "'");
        }
        mainWindow.addComponent(label);
        setMainWindow(mainWindow);
    }
    

    EDIT2:

    This is complete example that works for me. Try it, if it does not work for you please show your portlet.xml, web.xml and liferay-portlet.xml

    package com.test;
    
    import java.util.Iterator;
    
    import javax.portlet.PortletRequest;
    import javax.portlet.PortletResponse;
    
    import com.liferay.portal.kernel.util.WebKeys;
    import com.liferay.portal.model.User;
    import com.liferay.portal.theme.ThemeDisplay;
    import com.vaadin.Application;
    import com.vaadin.terminal.gwt.server.PortletRequestListener;
    import com.vaadin.ui.Component;
    import com.vaadin.ui.Label;
    import com.vaadin.ui.Window;
    
    public class Translation_portletApplication  extends Application implements PortletRequestListener {
    
        private User m_user;
    
        @Override
        public void init() {
            Window window = new Window("Vaadin Portlet Application");
            setMainWindow(window);
            String caption = "Hello Vaadin user!";
    
            if (m_user != null) {
                caption = caption + " with language id '" + m_user.getLanguageId() + "'";
            }
            window.addComponent(new Label(caption));
        }
    
        @Override
        public void onRequestEnd(PortletRequest p_request, PortletResponse p_response) {
            System.out.println("onRequestEnd");
        }
    
        @Override
        public void onRequestStart(PortletRequest p_request, PortletResponse p_response) {
            final ThemeDisplay themeDisplay = (ThemeDisplay) p_request.getAttribute(WebKeys.THEME_DISPLAY);
            m_user =  themeDisplay.getUser();
        }
    }
    

    EDIT3:

    For getting caption from your property files you can try with (assuming above class)

    Button button = new Button() {
        @Override
        public void attach() {
            ResourceBundle bundle = ResourceBundle.getBundle(Translation_portletApplication.class.getName(), user.getLocale());
            setCaption(bundle.getString("first_name"));
        }
    };
    window.addComponent(button);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to check that a user have logged in and been authenticated before
I need to check if my address has any words that matches word in
I need to check whether the logged in user is a administrator or non-admin
I need to check a pattern against some text (I have to check if
I need to check the user input in the preferences if they want to
i want something like this the user enter a website link i need check
I need to check programmatically (in .NET) whether a given user (domain account) is
I need to check for a string located inside a packet that I receive
I need to check that some content exists on the page within a specific
i need to check if a bucket exist on S3, and have following code:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.