JSF page navigation help

Splash Forums PrettyFaces Users JSF page navigation help

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

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #25193

    captainmorgan
    Participant

    I have a JSF 2.0 web app that stores every page in a database table. The table includes the “pretty” URL for the page.
    What I would like to do is, if you enter the URL “www.test.com/com/aboutus.html” This should access the actual page of “www.test.com/faces/pages.xhtml?url=%2Fcom%2Faboutus.html”

    Basically, any of my pages need to access the pages.xhtml file, passing in the pretty URL and displaying the pretty URL in the browser navigation bar.
    I think I should use Pretty Faces to do this, but I’m not sure how to set it up.
    Can someone help?

    #25195

    I recommend to have a look at Rewrite:

    http://ocpsoft.org/rewrite/

    Rewrite is something like the successor of PrettyFaces and allows to implement such requirements very easily. Basically you just have to add a rule like this:

    
    .addRule( Join.path("/{path}").to("/faces/pages.xhtml") )
    .where("path").matches(".*\.html")
    
    #25212

    captainmorgan
    Participant

    Thanks. That looks like what I want. However I have a couple of extra requirements that Iv’e just thought about.
    I have a page table and a page type table in my database, the page type table can refer to several different xhtml tables.
    To keep things simple. Lets say I have the following pages
    /com/aboutus.html – this would use /faces/pages.xhtml
    /com/general.html – this would use /faces/general.xhtml

    Can you create a rule to handle this?
    Also, my app will be running multiple copies of the website, displaying similar information.
    Can you have different rewrite configurations based on the website that is being accessed? If so, how?

    thank you

    #25214

    So you say the JSF view depends on the accessed URL and there is no naming pattern but you get this information only from the database? In this case it would perhaps make sense to build the configuration completely from the database. You could access the database from your configuration provider and then iterate over all your database entries and dynamically add multiple concrete joins like this:

    .addRule( Join.path("/com/aboutus.html").to("/faces/pages.xhtml") )
    .addRule( Join.path("/com/general.html").to("/faces/general.xhtml") )
    

    There is also a DomainName condition in Rewrite. So you can restrict rewriting rules to domain names. Something like this:

    .addRule( Join.path("/com/aboutus.html").to("/faces/pages.xhtml") )
    .when(Domain.matches("www.example.com"))
    
    #25216

    captainmorgan
    Participant

    Thanks, I’ll try that.
    Can you restrict by domain where it ends with certain characters (eg: “.zz”), rather than as specific match?

    #25217

    Yes, that’s possible:

    Domain.matches("{*}.zz")

    #25229

    captainmorgan
    Participant

    @RewriteConfiguration
    public class ApplicationConfigurationProvider extends HttpConfigurationProvider {

    @Override
    public Configuration getConfiguration(final ServletContext context)
    {
    return ConfigurationBuilder.begin()
    for (int i=1;1<10;i++) {
    .addRule(Join.path(“/”).to(“/pages/home.xhtml”))
    }
    }

    @Override
    public int priority()
    {
    return 0;
    }
    }

    #25233

    Beside the fact that you are adding the same rule 10 times, this should work fine. 🙂

    #25245

    captainmorgan
    Participant

    Thanks. I’ve finally got everything working.

    • This reply was modified 2 years, 9 months ago by  captainmorgan.
    • This reply was modified 2 years, 9 months ago by  captainmorgan.
    #25254

    Great! I’m glad that you got it sorted out! What was the problem with JPA? (I saw your email notification before your edit :))

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

You must be logged in to reply to this topic.

Comments are closed.