Re: Best Practices for PrettyFaces and Multiple language sites

Splash Forums PrettyFaces Users Best Practices for PrettyFaces and Multiple language sites Re: Best Practices for PrettyFaces and Multiple language sites

#20692

icordoba
Participant

Hello Christian,

thanks to your pretty:link example I’ve noticed I wasn’t adding the language as a parameter to h:link; I thought “en” could be set in a navigation rule and so make the links in the english home page be the same as in the main language. I’ll make the modifications to the links adding the parameter.

I’ve used pretty:link and it is also working great but, as I am using JSF2, I’ll try to use h:link whenever possible.

Now a new (small) issue: This is working great but as now I need to add the “language” parameter to the h:link for the english version I need to have multiple home sites, index.xhml for the standard home page (without any “es”, spanish, language prefix) and index_en.xhtml for the english home page, which adds the language parameter to the <h:link> tags.

To solve this I’ve tried to use the same index.xhtml and use “rendered” atribute in h:links:

<f:param rendered=”#{userSessionView.language!=’es’}” name=”language” value=”#{userSessionView.language}”/>

Which works ok for english (en), but if language is the “default” one in my site (es) I still get the link rendered to:

http://mysite.com/es/A/My+Article+Title

while it should be

http://mysite.com/A/My+Article+Title

Mapping:

<url-mapping id=”home”>

<pattern value=”/” />

<view-id>/index.jsf</view-id>

</url-mapping>

(no “language” parameter)

I’ve also tried pretty:link

<pretty:link mappingId=”#{userSessionView.language}ViewCMArticle”><f:param rendered=”#{userSessionView.language!=’es’}” value=”#{userSessionView.language}”/><f:param value=”My+title”/>My title…</pretty:link>

Which gets the right mappingId, but the problem seems to be in f:param, which doesn’t accept “rendered” attribute (is always rendered, and so I get a pretty error because this mapping expects just one parameter but get two, language and article title.

I know this is not a big deal now I’ve solved most of the problem. I can forget about “default” language and always use the same mapping /es/article+title, /en/article+title, … so I’lll stick to this as a last resort.

I hope I can get a “good practice” strategy for JSF2 SEO multilanguage sites (I’lll write a blog entry once I put this to work); a big problem for JSF2 users is that all online info about JSF and i18n starts from the assumption that the language is stored in the session and so user can change the language in the same xhtml page. That is fine for “applications” but is a big problem when you try to reuse JSF xhtml code for SEO friendly content management. Once I got to know about pretty faces I’ve had to rewrite some code to forget about storing language in session.

Thanks a lot again and thanks a lot OCPSoft for creating PrettyFaces,

Ignacio