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?

#23435

It seems like the redirecting doesn’t work from your action method. First you could try to replace encodeResourceURL with encodeActionURL because I’m no sure if the former once calls the required Servlet APIs for the rewriting to work correctly.

Another problem may be that you are using getRequestServletPath(). This one doesn’t refer to a JSF view id, so this won’t work. You current code returns something like this:

/my-context-path?faces-redirect=true&lang=en

This is not a valid JSF outcome because it doesn’t refer to a viewId. It should be something like this:

/welcome.xhtml?faces-redirect=true&lang=en

But you could also try to just manually redirect to the correct URL. Something like this:

String oldPath = PrettyContext.getCurrentInstance().getRequestURL().toString();
String newPath = oldPath.replace("/it/", "/en/");

FacesContext ctx = FacesContext.getCurrentInstance();
String contextPath = ctx.getExternalContext().getRequestContextPath();
ctx.getExternalContext().redirect(contextPath+newPath);
ctx.responseComplete();

Although the replace path should be implemented differently. :)