PrettyFaces and Dynamic Sitemap Generation

Splash Forums PrettyFaces Users PrettyFaces and Dynamic Sitemap Generation

This topic contains 9 replies, has 4 voices, and was last updated by  Christian Kaltepoth 7 years, 1 month ago.

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


    Has anyone done this? I saw where has a sitemap.xml and was curious how it was generated, if it was created dynamically, etc. My guess is it may be generated from a WordPress plug-in or similar but thought I’d ask.

    Ultimately, I was thinking of creating a class that read all of the url-mappings from pretty-config, iterated through each, built out full links using the url-mapping patterns (maybe via getPattern() ?), then utilizing those links to generate a sitemap.xml and populate a sitemap.jspx page.


    AFAIK the sitemap on is created by a WordPress plugin.

    Creating a sitemap using PrettyFaces is definitively possible this way. But I think this can only work for mappings without any path parameters. As soon as a mapping contains one or more path parameters the sitemap won’t be able to tell which values to insert there.




    Thanks Christian. Below is the approach I am taking at the moment. I am planning on retrieving the param names from the patterns via regex and exploding the urls dynamically for each mapping. Wish me luck!

    PrettyConfig config = PrettyContext.getCurrentInstance().getConfig();
    listOfMappings = config.getMappings();

    for (UrlMapping mapping : listOfMappings) {
    // get values
    String id = mapping.getId();
    String pattern = mapping.getPattern();

    // parse pattern, get possible param values & create dynamic urls here




    This should definitely work. Just make sure you take a look at PrettyURLBuilder. It should have some methods that will make this easier for you.





    This topic is helpful for me, since I want to generate sitemaps.

    However my code is inside @Singleton bean, so it’s not part of JSF but EJB, and PrettyContext.getCurrentInstance() gives an error.

    How can I make this work?


    How is this EJB packaged? Is it inside the WAR or in a separate JAR inside an EAR? However I’m note sure this will work correctly as PrettyContext.getCurrentInstance() is using FacesContext.getCurrentInstance() internally which may not work from EJBs.

    But there are other ways of obtaining the PrettyConfig instance. For example:

    PrettyConfig prettyConfig = (PrettyConfig) servletContext.getAttribute(PrettyContext.CONFIG_KEY);

    However, you will need to have access to the ServletContext in this case. Please be aware that PrettyFaces always initializes itself for one web application, so you will definitively have to use something like the ServletContext to access the PrettyFaces configuration.



    How can I access ServletContext from EJB Bean? Inject isn’t working. PrettyContext.getCurrentInstance() is not working too.


    Try injecting HttpServletRequest and then use PrettyContext.getCurrentInstance(request).getConfig()



    With @Inject? It returns null.


    Is the bean called in the context of a request?

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

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

Comments are closed.