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 2 years, 5 months ago.

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

    clemmonsm
    Participant

    Has anyone done this? I saw where ocpsoft.com 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.

    #21774

    AFAIK the sitemap on ocpsoft.com 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.

    Christian

    #21775

    clemmonsm
    Participant

    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

    }

    #21776

    Hey!

    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.

    -Lincoln

    #21777

    m1m
    Participant

    Hey

    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?

    #21778

    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.

    #26582

    m1m
    Participant

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

    #26585

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

    #26589

    m1m
    Participant

    With @Inject? It returns null.

    #26601

    Is the bean called in the context of a request?

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

You must be logged in to reply to this topic.

Comments are closed.