Set preferred language - Websphere

This is a discussion on Set preferred language - Websphere ; Hello all! I'm looking for a way for a user to be able to choose the language he will see in the portal and all the WPF portlets in the login page (portlet). I want to add a field to ...

+ Reply to Thread
Results 1 to 13 of 13

Thread: Set preferred language

  1. Set preferred language

    Hello all!

    I'm looking for a way for a user to be able to choose the language he will see in the portal and all the WPF portlets in the login page (portlet). I want to add a field to the login page where the user chooses his preferred language. When processing the login request, I want the set the user preferred language so that when he logs in, he will se the portal using the language he chose.

    Is there a way to do this when processing the login request?

    Thanks in advance,
    Hugo Madureira

  2. Re: Set preferred language

    one option is to use the theme tag,

    these generate links to change the language.

    So what you could do is to have a drop down list with the available languages on the login page, when someone chooses a different language in this dropdown list then the link is activated and the page is reloaded in the selected language.

    not precisely what you asked for but gets the job done.

    you might also be able to use the url generation api for this.

  3. Re: Set preferred language

    If I place that tag in the portal theme, it works. My problem is that if a portlet (designed in portlet factory) have been viewed already, changing the portal language will not update that portlet language.

    Placing the tag in the login portlet will not work (my login page only displays the login portlet), as the taglib is not available outside the portal theme. I wonder if there is any portal api available from my custom portlet jsp code that can generate the same url that changes the portal language. This would solve the problem, as the user would login already with his preferred language.

    I've looked in the portal information center but about the url generation, I can't find a way to create a url command that changes the portal language.

    Any help on this?

    Thanks again,
    Hugo Madureira

  4. Re: Set preferred language

    Did you review this section of the InfoCenter?:

    It seems like preferredLanguage (assuming your user repository supports it) could be set through Self Care / Edit My Profile for this purpose.

  5. Re: Set preferred language

    Yes, I did read that section of the InfoCenter.

    My problem is I don't want the user to edit his profile. The language must be selected from the login page (portlet). That's why I want to be able to set the user preferred language from the code processed after the login submission.

  6. Re: Set preferred language

    I have a code that I used to set manually user's preffered language. Code is attached.

    updateUserLocale() method is responsible to set the user language on preferences.
    reloadPortalUser() methos is used to refresh user's info so portal can recognize his new language and properly render website.

    {code}String strLocale = 'es';
    Locale newLocale = LocaleUtils.parseLocale(strLocale); user = PortalUtil.updateUserLocale(newLocale, request);
    PortalUtil.reloadPortalUser(user, request);{/code}

  7. Re: Set preferred language

    Hello Moretti,

    I've looked into your code but I cant't find some of the classes you use. Are the LocaleUtils and PortalUtil classes developed by you? Can you please provide me with that code?

  8. Re: Set preferred language

    Is the PortalUtil class referenced here available in developworks or can you please post it. I would also find this very useful. thanks.

  9. Re: Set preferred language

    Sorry for long delay to respond to this thread. The PortalUtil class is attached.

  10. Re: Set preferred language

    should be attached now

  11. Re: Set preferred language

    import java.util.HashMap;
    import java.util.Locale;

    import javax.naming.InitialContext;
    import javax.servlet.http.HttpServletRequest;


    public class PortalUtil
    private static final String LDAP_LANG_ATTR = "preferredLanguage";

    public static updateUserLocale(Locale newLocale, HttpServletRequest request) throws Exception
    InitialContext ctx = new InitialContext();
    PortletServiceHome portletServiceHome = (PortletServiceHome)

    PumaHome pumaHome = (PumaHome) portletServiceHome.getPortletService(PumaHome.clas s);

    PumaController pumaController = pumaHome.getController();
    PumaProfile pumaProfile = pumaHome.getProfile(); user = pumaProfile.getCurrentUser();

    System.out.println("PortalUtil:: User:" + user.toString());

    HashMap userAttrs = new HashMap();
    userAttrs.put(LDAP_LANG_ATTR, newLocale.toString());
    pumaController.setAttributes(user, userAttrs);

    System.out.println("PortalUtil:: User updated - " + newLocale);
    return user;

    public static void reloadPortalUser(User user, HttpServletRequest req)
    { objectid = user.getObjectID(); user1 = ( req.getAttribute(""); objectid1 = user1.getObjectID();
    System.out.println("PortalUtil:: User "+ user1.getFullName() +" reloaded...");
    catch(Exception exception)
    System.out.println("PortalUtil:: not same object id");
    System.out.println("PortalUtil:: objectid: " + objectid);
    System.out.println("PortalUtil:: objectid1: " + objectid1);

  12. Re: Set preferred language

    thanks for posting your code. I was able to write my own reload() method yesterday based based on your first post and it turns out that it is very similar to your code, so thank you for helping verify it.

  13. Re: Set preferred language

    I'm trying to do something similar, and I even have a similar reload method, but I'm running into some trouble.

    We have an organization history of client data stored in all sorts of disparate systems, and to say it is non-trivial to move it into the LDAP user registry is an understatement. In fact the first page a user sees on the portal is actually after they log in, their identity being asserted through other mechanisms then the portal login page. My issue is that as we don't have language in ldap, I can fetch the proper language while rendering the theme, set the clients preferred language with the PUMA SPI, and even trigger a reload very similar to the one in the code posted above. But neither my theme nor my portlets respect the language change until the client clicks on any link (that is all subsequent renders respect the clients preferred language now.)

    In essence every time the client changes their language through a mechanism outside of portal, they must view at minimum one page in their old language, or for clients who are using our portal for the first time must see at least one page in the default language and not necessarily their own.

    I figure there are one of two possible solutions two this problem, I just don't know if portal can do either of them.

    1. a reload that reloads in place, maybe I need to put the language setting logic in another location so that it kicks in before the theme? Or their is another way to kick off a reload that is more aggressive.

    2. Set a parameter on the url that forwards the client to portal from the authentication method that encodes the language, so that the first page renders from the URL set language, while my logic keys in their new language choice, and then even if that URL param is lost it is only required on the first page.

    I would prefer 1, but 2 would be really easy to code, I just don't know if there is a parameter that portal would honor?

    Any help would be great!

+ Reply to Thread