Reply To: SEO URL supporting l10n/i18n with PrettyFaces

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

#23542

Stephan Rudolph
Participant

Hello,now we are in process of switching from <strong>prettyfaces</strong> to <strong>rewrite</strong>.What we like to do is as follows:<ol>    <li>        Case: Request from outside without <code>LOCALE</code>, <code>PATH</code> and <code>VIEW</code> information (homepage)        <code>/</code> to <code>/pages/index.xhtml</code>        <code>localehandler.localeselected</code> becomes set by evaluation of the HTTP header element <code>Accept-Language</code> and the JSF configuration elements <code>supported-locale</code> as well as <code>default-locale</code>    </li>    <br/>    <li>        Case: Request from outside with <code>LOCALE</code>, <code>VIEW</code> or <code>PATH</code> and <code>VIEW</code> information (bookmark)        <code>/LOCALE/VIEW</code> to <code>/pages/VIEW</code>        <code>/LOCALE/PATH…/VIEW</code> to <code>/pages/PATH…/VIEW</code>        <code>localehandler.localeselected</code> becomes set by <code>LOCALE</code>    </li>    <br/>    <li>        Case: Request from internal (navigation)        <code>/pages/VIEW</code> to <code>/LOCALE/VIEW</code>        <code>/pages/PATH…/VIEW</code> to <code>/LOCALE/PATH…/VIEW</code>        <code>LOCALE</code> becomes set by <code>localehandler.localeselected</code>    </li>    <br/></ol><ul>    <li>        <code>LOCALE</code> stands for an element of the URL representing the locale (e.g. <code>de-CH</code>, <code>en-US</code>, …)    </li>    <li>        <code>PATH</code> stands for any path element of an URL (e.g. <code>/company/location/</code>)    </li>    <li>        <code>VIEW</code> stands for the view (e.g. <code>services.xhtml</code>)    </li></ul>There is also a session scoped managed bean, named localehandler.The property <code>localehandler.localeselected</code> represents the current locale of the view (f:view locale) and becomes set by:<ul>    <li>        evaluation of the HTTP header element <code>Accept-Language</code> and the JSF configuration elements <code>supported-locale</code> as well as <code>default-locale</code> – if there is no other input (<code>LOCALE</code> element or user input)    </li>    <li>        <code>LOCALE</code> element of the URL    </li>    <li>        explicitly, by the user, via a select menu (deutsch, english, french, …)    </li></ul> In order to implement the 1st case , we use the code:<code>@Overridepublic Configuration getConfiguration(final ServletContext context) {    return ConfigurationBuilder.begin()        .addRule(Join.path(“/”).to(“/pages/index.xhtml”))        ;}</code>That works very well :-).In order to implement the 2nd case, we use the code, mentioned earlier in this thread:<code>@Overridepublic Configuration getConfiguration(final ServletContext context) {    return ConfigurationBuilder.begin()        .addRule(Join.path(“/”).to(“/pages/index.xhtml”))        .addRule(Join.path(“/{lang}/{path}”)            .where(“lang”).bindsTo(El.property(“localeHandler.languageSelected”))            .where(“path”).matches(“.*”)            .to(“/pages/{path}”))        ;}</code>This results in the exception as follows:<code>[#|2013-04-12T23:10:53.611+0200|SEVERE|glassfish3.1.2|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=78;_ThreadName=Thread-2;|WebModule[]PWC1270: Exception starting filter OCPsoft Rewrite Filterjava.lang.InstantiationException…Caused by: java.lang.NullPointerException…</code>   Now, my question is: What code does we need, in order to implement the 2nd and 3th case the right way?