Problem with link generation with language parameter.

Splash Forums PrettyFaces Users Problem with link generation with language parameter.

This topic contains 6 replies, has 2 voices, and was last updated by  Marcin Kapusta 8 years, 5 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
  • #24457

    Marcin Kapusta

    I have difficulty to make this simple example to work.

    My configuration: JSF 2.1.24, Pretty Faces 3.3.3, Tomcat 7.0.42

    I have such mapping:

    <url-mapping id="base">
      <pattern value="/#{ /pl|en|de/ locale.language }" />
    <url-mapping id="home" parentId="base">
      <pattern value="/" />
      <view-id value="/views/home.xhtml" />

    In my /views/home.xhtml i have such link

    <h:link outcome="pretty:home" value="Home" />

    And my bean is like that

    import javax.annotation.PostConstruct;
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.RequestScoped;
    @ManagedBean(name = "locale")
    public class LocaleBean {
    	public static final String DEFAULT_LANGUAGE = "pl";
    	private String language;
    	public void init() {
    		this.language = DEFAULT_LANGUAGE;
    	public String getLanguage() {
    		System.out.println("getLanguage: " + language);
    		return language;
    	public void setLanguage(String language) {
    		System.out.println("setLanguage: " + language);
    		this.language = language;

    When I enter to the link that is generated on home view is like that:

    <a href="/web-base/views/home.xhtml?com.ocpsoft.mappingId=home">Home</a>

    The question is. Why the link is not like that?:

    <a href="/web-base/en/">Home</a>

    The web-base is the context path and in my console I have such output:

    setLanguage: en

    What Am I doing wrong? Can somebody help?


    This is very strange. Could you perhaps try the latest version of PrettyFaces? See for instructions. If this is still failing, would you mind uploading a sample application that we can use to test your problem?

    I’m sorry you are having trouble.



    Marcin Kapusta


    I get it to working by write link in this way:

    <h:link outcome="pretty:home" includeViewParams="true">

    The includeViewParams was needed.

    Also I had f:viewParam defined in the master template and this is bad idea. I moved it to my view and insert it under f:metadata, and now it works. There is still problem with language parameter that exists on every page and I can’t put it in the master template. I have to manualy provide the value of the parameter like this:

    <h:link outcome="pretty:home" includeViewParams="true">
      <f:param name="language" value="#{localeBean.language}" />


    • This reply was modified 8 years, 5 months ago by  Marcin Kapusta.
    • This reply was modified 8 years, 5 months ago by  Marcin Kapusta. Reason: formatting

    Strange. Maybe this is something that changed in one of the most recent versions of JSF. Do you think you could upload an example so that I could play with it on some servers?

    Glad you got a workaround, though!



    Marcin Kapusta


    I attached my project from eclipse. It use maven 3 pom.xml
    I running it on Tomcat 7.0.42, Java 7, Windows 7 32 bit

    When You run it, type in your browser http://localhost:8080/web-base/pl/

    Take a look at 3 links “About Us”.

    After reading this article: which help me a lot about understandings some concepts about url and parameters in JSF 2 I noticed that when I add to the view/about-us.xhtml file such lines after the line: template=”/WEB-INF/templates/base.xhtml”>

      <f:viewParam name="language" value="#{locale.language}" />

    Then on the page http://localhost:8080/web-base/pl/ second and third link (About Us) is generated correctly.
    It seems that in view I have to define metadata with viewParam’s when I want to use pretty faces to generate link to this view with parameters. Also note that the includeViewParams=”true” must be provided because default value of this attribute is false.


    • This reply was modified 8 years, 5 months ago by  Marcin Kapusta. Reason: formatting, spelling
    • This reply was modified 8 years, 5 months ago by  Marcin Kapusta.
    • This reply was modified 8 years, 5 months ago by  Marcin Kapusta.

    Hi Marcin,

    Thanks for posting your example – apologies that I did not see it sooner. Our forums had a problem sending notification emails for a few days, and I’ve been on Vacation, so I was not monitoring as aggressively 🙂

    Do I understand correctly that you’ve found the solution for your issue? If not, just let me know and I’ll take a deeper look.



    Marcin Kapusta

    Yes I found a solution and after that I switch to the Rewrite. Thankt for reply.


Viewing 7 posts - 1 through 7 (of 7 total)

The forum ‘PrettyFaces Users’ is closed to new topics and replies.

Comments are closed.