Re: multi-language url rewiting. Is it possible?

Splash Forums PrettyFaces Users multi-language url rewiting. Is it possible? Re: multi-language url rewiting. Is it possible?

#23434

francescanye
Member

Thanks, the picture is getting clearer. I prefer to use the pretty:link and it work perfectly!

Now I’m stuck on a commandLink, the one I used to change the language by clicking on a flag icon: when I ckick the flag, the url does not change the first time. It willl change if I click once more the flag or I navigate away from the page. Maybe this is a small issue but even adding ?faces-redirect=true the problem persists. Is there something related to pretty-faces?

Here is the xhtml snippet:

<h:commandLink immediate="true"
action="#{localeChanger.changeLocale('en')}">
<h:graphicImage library="images" name="flags/flag_eng.gif" />
</h:commandLink>

Here is the action:

public String changeLocale(String lang) {
languageCode = lang;
FacesContext context = FacesContext.getCurrentInstance();
context.getViewRoot().setLocale(new Locale(languageCode));
String path = context.getExternalContext().getRequestServletPath();

String rewrittenURL = context.getExternalContext()
.encodeResourceURL(path+"?faces-redirect=true&lang="+languageCode);
System.out.println("changeLocale:"+rewrittenURL);
return rewrittenURL;
}

So rewrittenURL is correct (/mtc/en/main/welcome?faces-redirect=true) but the url in the address bar does not change.

The commandLink is part of the template so it is on every pages, also on those pages where the url-rewriting is not necessary.