Prettyfaces issue when using with viewparam converter

Splash Forums PrettyFaces Users Prettyfaces issue when using with viewparam converter


This topic contains 7 replies, has 3 voices, and was last updated by  Christian Kaltepoth 2 years, 12 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
  • #18800


    i’m using jsf 2.1, prettyfaces 3.3.3 and hibernate jpa 3.6.7. i have country page and i’m trying to send comment with commandbutton.


    <html xmlns=""
    <f:viewParam name="country" value="#{countryBean2.selectedCountry}" converter="countryConverter"
    required="true" />
    <h:form id="form">
    <h:outputText value="#{countryBean2.selectedCountry.countryName}" />
    <h:outputText value="Comment:" />
    <h:inputText value="#{countryBean2.comment}" />
    <h:commandButton value="Send" action="#{countryBean2.sendComment}" />


    public class CountryConverter implements Converter {
    public static EntityCountry country = new EntityCountry();

    EntityManagerFactory emf = Persistence.createEntityManagerFactory("testPU");

    public EntityCountry getAsObject(FacesContext context, UIComponent component, String value) {
    EntityManager em = emf.createEntityManager();
    Query query = em.createQuery("SELECT c FROM EntityCountry c WHERE c.url = :url")
    .setParameter("url", value);
    country = (EntityCountry) query.getSingleResult();
    return country;

    public String getAsString(FacesContext context, UIComponent component, Object value) {
    EntityCountry c = (EntityCountry) value;
    return c.getUrl();


    <pretty-config xmlns=""

    <url-mapping id="home">
    <pattern value="/" />
    <view-id value="/faces/index.xhtml" />

    <url-mapping id="country">
    <pattern value="/country/#{country}" />
    <view-id value="/faces/country.xhtml" />


    converter configuration in faces-config.xml:


    when i open localhost:8080/test/country/england page firstly, everything works well. but when i try to send comment via commandbutton, countryConverter’s getAsObject method is calling again with wrong string parameter (such as “test.CountryBean@bd9eff”) and entity can not be found.

    when i use with default ugly url (such as localhost:8080/test/faces/country.xhtml?country=england) and try to send comment, countryConverter’s getAsObject method is calling with true string parameter and i can send comment successfully.

    i also asked this question before there: but it was not resolved.


    First, please do not paste HTML formatting into code snippits. I had to go back and clean up your post. It helps us answer you faster if you make sure it looks good :)

    Now that that’s out of the way!

    Could you please upload a small example project that we can use to reproduce this problem? I think we need to debug to figure out what is going on. Otherwise, if you want, take a look in PrettyActionHandler and see if you can figure out why the link is being converted “too aggressively.”

    Sorry your first post was not answered to your satisfaction. I believe it was left after I asked you to upload a simple project with as few dependencies as possible, that way we could actually build and run it. Hopefully you can do this, because it sounds like a very complicated issue and we need to be able to look at the actual code and debug it!




    A simple JPA / JSF / PrettyFaces project would be best.


    Just for the sake of completeness. Here is the corresponding stackoverflow post:



    hey i found the mistake when i try to make simpler example. i have another managed bean that named with “country” and i have pattern value named with “country” in pretty-config.xml.

    public class CountryBean implements Serializable {

    when i change @Named(“country”) value, it is working successfully. but i don’t understand relationship between @Named annotation and prett-config.xml.


    Awesome! Glad you solved it! I figured it was something weird like that, but I was also scared it was going to be a bug :) We haven’t had any bugs from this before so it would have been interesting (scary) to debug ;)



    AFAIK for a pattern like /country/#{country} PrettyFaces also interprets country as an EL expressions and tries to set the path parameter value (which will usually work). Perhaps this is related?

    I would like to change this behavior, but I’m afraid it may break other peoples code. Especially because people may use #{country} inside the page for displaying it or something like this.


    BTW: This explains why the URL renders to: test.CountryBean@bd9eff


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

You must be logged in to reply to this topic.

Comments are closed.