Dynamic view id using pretty faces navigation refuses to work

Splash Forums PrettyFaces Users Dynamic view id using pretty faces navigation refuses to work

This topic contains 8 replies, has 3 voices, and was last updated by  Lincoln Baxter III 7 years, 3 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
  • #26456


    I am attempting to migrate an application from JSF 1.2 to JSF 2.1. The code below worked in the 1.2. I am using PrettyFaces 3.3.3, MyFaces 2.1.

    in pretty-config.xml:

    <url-mapping id="seSite">
      <pattern value="/sites/#{seViewChooserBean.urlSiteType}/#{seViewChooserBean.siteId}"/>
      <view-id value="#{seViewChooserBean.getSiteViewId}"/>
    <url-mapping id="seSiteProps">
      <pattern value="/sites/#{sePropsBean.urlSiteType}/#{sePropsBean.siteId}/properties"/>
      <view-id value="/pages/se/site/props.xhtml"/>

    I have a request with URL: http://example.com/myapp/sites/object/309847 This request successfully matches the url mapping id “seSite” and getSiteViewId is invoked on seViewChooserBean and returns the result “pretty:seSiteProps”. I have debugged and confirmed this. For your reference this is the bean code for ViewChooserBean.java:

    public String getSiteViewId() {
        if (siteType == SiteType.TYPE) {
            // redirect to tag list view
            initSiteBean("seTagListBean", TagListBean.class);
            return "pretty:seTagList";
        else {
            // redirect to site properties view
            initSiteBean("sePropsBean", PropertiesBean.class);
            return "pretty:seSiteProps";

    After that prettyfaces then attempts to forward to the new view id seSiteProps but the new generated URL is not processed by pretty faces because (from the logs): “Request is not mapped using PrettyFaces. Continue.”

    So I get 404 response for URL http:://example.com/myapp/sites/object/309847/properties.

    Note that this url match to view id seSiteProps.

    I have debugged this up into the pretty faces filter and discovered the following:

    After the initial request for http://example.com/myapp/sites/object/309847, the DynaviewEngine.processDynaView is invoked and generates the correct target url http:://example.com/sites/object/309847/properties and forwards via faces request.

    Then, with a breakpoint in PrettyFilter.doFilter() I observed the following: In PrettyFilter.doFilter() method: isUrlMappingForward(req) returns false, therefore request is not processed by prettyfaces. Why??

    // isUrlMappingForward returns false.  The request has url http:://example.com/myapp/sites/object/309847/properties on it.
    if (!isUrlMappingForward(req))
      mapping = getConfig().getMappingForUrl(url);

    Also, note that if I put the request http:://example.com/myapp/sites/object/309847/properties directly in the browser the page IS processed by prettyfaces and isUrlMappingForward(req) returns true and it loads correctly in the browser.

    I was thinking I’ve missed something obvious here as the problem hasn’t been reported elsewhere as far as I can tell. Any help is greatly appreciated. Thanks. Brett


    Hmmm, it looks like you may have found a bug. But you should probably upgrade to Rewrite Config PrettyFaces 2.0.12 (the latest version.) Please see more instructions here! –> http://ocpsoft.org/prettyfaces/#section-4

    Sorry for the version number confusion. PrettyFaces is now an extension of Rewrite.



    Thanks for the response. Unfortunately I’m seeing the same behaviour for both versions. I was testing with 3.3.3 just so I could see what was happening in PrettyFilter. Is what I’m doing an unusual usage of Pretty Faces? Otherwise I thought this would be a pretty major bug, or, I’m doing something wrong. Is there another way to achieve the same thing?
    Thanks a lot

    • This reply was modified 7 years, 3 months ago by  brettw.

    See my answer on your stackoverflow question:


    I’m not sure if this ever worked correctly. I think returning PrettyFaces navigation strings from dynaview methods was never supposed to work.

    @lincoln: Or am I wrong?


    Ah, whoops. Actually you are correct Christian! http://ocpsoft.org/docs/prettyfaces/3.3.3/en-US/html/Configuration.html#config.dynaview

    DynaView does not support returning pretty:mapping strings!



    Ok thanks. Really interesting that it worked in JSF 1.2 version. In my debugging it looked like there was only one line of code stopping this functionality from working ie the urlMappingForward check. It was introduced to fix another bug (fix #150 or something like that). Would be a good feature to have in my opinion.


    Hmm, I do remember playing with this feature early on. I do seem to recall that it would allow this kind of behavior. I don’t remember if there was a reason for removing it, or if it was just an oversight. Since it sounds like you found what is preventing this from working, would you be interested in submitting a patch/pull request to make this work again? Either that or submit a test case, tell me where to check, and I will take a look!


    That being said, have you looked at using Rewrite instead of PrettyFaces in this case? I believe it should allow you to do everything you need, without needing the dynaview functionality. (It supports dynamic routing out of the box as a top-level feature.)



    Also, for clarification’s sake, the latest version of PrettyFaces (at http://ocpsoft.org/prettyfaces/) actually is a Rewrite extension, so you would get both anyway if you upgraded from PF 3.3.3 to Rewrite 2.0.12

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

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

Comments are closed.