Achieved this by creating a Session scoped bean and putting requested language as a query parameter, then using pages.xml action which are fired before page in rendered to set current locale
SEAM / Java EE - Set Locale From Domain
Pergunta
I have a SEAM 2.2.2 App running on JBoss AS6
The App is setup with a number of languages
In the JBoss deploy directory /jbossweb.sar/server.xml I have mapped a number of different domains using the following Host entries
<Host name="myApp">
<Alias>www.myapp.com</Alias>
<Alias>myapp.com</Alias>
<Alias>www.myapp.sv</Alias>
<Alias>myapp.sv</Alias>
<Valve className="org.apache.catalina.valves.AccessLogValve"
prefix="processor" suffix=".log" pattern="common"
directory="${jboss.server.home.dir}/log"/>
<Valve className="org.jboss.web.tomcat.service.jca.CachedConnectionValve"
cachedConnectionManagerObjectName="jboss.jca:service=CachedConnectionManager"
transactionManagerObjectName="jboss:service=TransactionManager" ></Valve>
</Host>
We need to be able to ensure that all visitors who land on www.myapp.sv have the default language set to swedish even if their browser defaults to english
What would be the best way to achieve this? My initial guess would be to check which locale is set when the page is requested then use Seam's localeSelector to override the default set by the browser but this seems like a bit of a hack and potentially wasteful as the resource bundles would be loaded then reloaded?
Is there any way to 'intercept' the initial locale selection and override it with one based on the domain extension?
Thanks
Solução 2
Outras dicas
Make a startup LocaleBean and set the desired locale.
Thus something like this:
@Startup
@Scope(APPLICATION)
@Name("LocaleBean")
public class LocaleBean {
@Create
public void init() {
FacesContext.instance().getViewRoot().setLocale(new Locale("SV"));
}
}