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?



The only way to get it to work was using the redirect, thanks.

The initial redirection to the welcome file is the only item I’m still having concern on. Fixed redirection to the italian content welcome file was not an acceptable solution, so I tried something different. I removed the <welcome-file-list> element completely from the web.xml file and I developed a simple filter:

<!--  Default page -->

and inserted just before the pretty-faces filter:

public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
// Request and Response
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
// Session
HttpSession session = httpRequest.getSession();
// Get the localeChanger bean
ChangeLocaleBean clb = (ChangeLocaleBean)session
String lang = "en";
if(clb == null){
// here the localeChanger is null: no info ubout the language,
// so the language is taken from the request
Locale loc = httpRequest.getLocale();
if(loc != null)
lang = loc.getLanguage().toString();
} else {
// there is a session parameter about the language: we use
// that one
lang = clb.getLanguageCode();
String url = httpRequest.getRequestURL().toString();
if (httpRequest.getQueryString() != null) {
url = url + "?" + httpRequest.getQueryString();

StringBuilder redirectUrl = new StringBuilder(url);

// redirect 301
httpResponse.setHeader("Location", redirectUrl.toString());

"no-cache, no-store, must-revalidate"); // HTTP 1.1.
httpResponse.setHeader("Pragma", "no-cache"); // HTTP 1.0.
httpResponse.setDateHeader("Expires", 0); // Proxies.

which will be called on / path only and remap it into the welcome page with the content in the appropriate language:

If the language has already been set in the session (flag link clicked), use that language,

otherwise use the language coming from the user request.

Furthermore, in order to avoid the user to go to the “back-end” welcome page I’ve used:

<rewrite match="/pages/main/welcome.jsf"
redirect="301" />

which triggers the filter just in case.

It works as expected, but I wonder if it is the right way to do it. Could I use pretty-faces features only instead of implementing a filter? Am I misusing pretty-faces?