Jan 6, 2012, 12:21 PM
150 Posts

How to override the html lang attribute

  • Category: Server Side JavaScript
  • Platform: All
  • Release: 8.5.3
  • Role: Developer
  • Tags:
  • Replies: 4
I need to override the html "lang" attribute in my xpage, and set a language based on a what is in a user profile.
in the xpage properties I can set a default language, but this is only used if the browser has no language set. 
I always want the language set in the user profile to be the correct language 
I have tried to add an xpage attribute (attrs) and this will set the lang attribute but now I got two lang attributes like this: html lang="sv" lang="en" and it is not working.
I could use context.setLocaleString("sv") in every  xpage on beforePageLoad, but this does not really work very well as I then need to reload the page in code to get it working. beside it is not a very nice solution.
Jan 9, 2012, 4:43 PM
122 Posts
Re: How to override the html lang attribute
In the absence of any other ideas, I'll throw a couple of thoughts.
Is the setting to aggregate JavaScript and CSS files switched on? I found that overrode my attempts to change the Dojo version for the NSF because of what gets pushed out in the plugin. If so, try disabling that. Just a total stab in the dark, but may be the reason for Lang tag getting pushed in regardless of your settings.
The other thought is using a meta tag resource. Will that work?
A third one I've just thought of is themes. Because themes get applied right at the end of the JSF lifecycle, setting something on the ViewRoot control may override what XPages is applying, especially with override="true".
I haven't tried any, but just a few thoughts in the absence of any other suggestions.
Jan 10, 2012, 1:06 AM
150 Posts
Re: How to override the html lang attribute
The reason I need to override the html lang attributes is only because I want the language used to be controlled by a user profile. (maybe override is the wrong word)
currently, the language users get, is controlled by the settings in the webbrowser.
in other words, I want the user to be able to switch language permenently without changing the broser settting.
Jan 12, 2012, 8:44 AM
272 Posts
Re: How to override the html lang attribute
maybe this goes to the wrong direction, but you could add your own ViewHandler. This would you allow to control the language application wide.
To do this, you have to create a java class like this:
package ch.hasselba.xpages.debug;

import java.util.Locale;
import javax.faces.context.FacesContext;
import javax.faces.application.ViewHandler;

public class ViewHandlerSH extends com.ibm.xsp.application.ViewHandlerExImpl {

    public Locale calculateLocale(FacesContext arg0) {
return Locale.CHINESE;

    public ViewHandlerSH(ViewHandler paramViewHandler){

Add the code you want for the calculation in the method calculateLocale. For example you could do the lookup to the user profile here, or get settings from the session scope.
Then, you have to register the view handler in the faces-config:
<?xml version="1.0" encoding="UTF-8"?>
This example will always return chinese as preferred language.
Hope this helps
Jan 25, 2012, 8:47 AM
150 Posts
Re: How to override the html lang attribute
 Thank you Sven, I will try it!