Re: SEO URL supporting l10n/i18n with PrettyFaces

Splash Forums PrettyFaces Users SEO URL supporting l10n/i18n with PrettyFaces Re: SEO URL supporting l10n/i18n with PrettyFaces

#23443

Hey,

I think there are a few ways to achieve what you want. The first idea is to introduce a parent mapping for all your existing mappings that includes the language code. Something like this:

<url-mapping id="base">
<pattern value="/#{ lang : localeBean.lang }" />
</url-mapping>

<url-mapping id="welcome" parentId="base">
<pattern value="/welcome" />
<view-id value="/faces/welcome.xhtml" />
</url-mapping>

and a bean like this:

@Named
@RequestScoped
public class LocaleBean {

private String languageCode;

/* getters / setters */

public Locale getLocale() {
return new Locale(languageCode);
}

}

And a view configuration like this:

<f:view locale="#{localeBean.locale}">
...
</f:view>

I think think this setup will work fine. The only problem will be, that you will have to adjust all your <pretty:link> and <h:link> components to include the value of the lang parameter. Something like this:

<pretty:link mappingId="welcome">
<f:param value="#{localBean.lang}">
</pretty:link>

or:

<h:link outcome="/welcome.xhtml">
<f:param name="lang" value="#{localBean.lang}" />
</h:link>

If you are looking for a simpler solution, you should have a look at Rewrite, which is the successor of PrettyFaces. I think it could be possible to implement something like this so that you won’t have to adjust much code. But I’m not completely sure how this would look like. But with Rewrite you can do EVERYTHING. :)

Have a look here:

Rewrite

and especially:

http://ocpsoft.org/rewrite/examples/