5 Replies Latest reply on Aug 26, 2006 6:13 AM by tluzat

    Friendly URLs (e.g. /request/parameter1/parameter2)

    tluzat

      I would like to use "friendly URLs" in some places of my application. Examples would be:

      http://www.example.com/gallery/20/12
      http://www.example.com/articles/some-interesting-article

      vs.

      http://www.example.com/gallery?id=20&img=12
      http://www.example.com/articles?name=some-interesting-article

      Are there any (decent, non-hackish) ways to do that using Seam? It wouldn't be too hard to rewrite incoming URLs in Apache or later on, but what about the URLs generated by the JSF/Seam tags?

      Having to rewrite URLs does look kind of hackish to me, too. I'd prefer to plug in some sort of parser and generator for certain requests.

      Thanks for any input :-)

        • 1. Re: Friendly URLs (e.g. /request/parameter1/parameter2)
          robjellinghaus

          See this thread:
          http://www.jboss.com/index.html?module=bb&op=viewtopic&t=89017

          The party line seems to be that details of URL formats are properly the concern of the webapp, not Seam. So use a Tomcat plugin or Apache plugin or something to mung your URL into request parameters that work with Seam out of the box.

          • 2. Re: Friendly URLs (e.g. /request/parameter1/parameter2)
            robjellinghaus

            Actually I found another thread that indicates you can potentially do some of this sort of thing in pages.xml, but the details are tenuous. Sorry I don't have the thread link handy (and I should be working, not Seam hacking, anyway ;-).

            • 3. Re: Friendly URLs (e.g. /request/parameter1/parameter2)
              tluzat

              Thanks!

              Looking through the forums and the blog example I got some ideas:

              -For requests pages.xml can be used for view-ids such as article/* and gallery/*. The actions called can then use a FacesContext to get the parameters encoded in the URL through facesContext.getExternalContext().getPathInfo().

              -For generated links (s:link, h:outputLink, ...?) I'll have to supply alternatives (extended versions) which support alternative ways of formatting the result, probably through a formatter class.

              I haven't tested any of these and actually not written any code using Facelets and Seam yet, but does this sound reasonable? :-) I'll run some tests tomorrow. If it works it might be worthwhile to add extended tags (s:link, ...) which support different URL formatters and actions which parse different types of URLs to the Seam distribution. Please comment!

              • 4. Re: Friendly URLs (e.g. /request/parameter1/parameter2)
                perwik

                To quote myself from an other thread

                Url Rewrite Filter, mod_rewrite for the Java world:

                http://tuckey.org/urlrewrite/


                I really think you should have a good look at it.

                • 5. Re: Friendly URLs (e.g. /request/parameter1/parameter2)
                  tluzat

                  You're right. I'll probably resort to URL rewriting after having read

                  http://www.jboss.com/index.html?module=bb&op=viewtopic&t=85269

                  and trying to get it to work by myself. I don't like the quite static coupling between URLs and the way they're interpreted from a design point of view, but that's what we've got and rewriting seems to be the most practical solution here.

                  After having spent some more time on use cases rewriting s:links doesn't make sense anymore here and as far as I can tell now I'll probably just supply a function to convert a request and actions into request/parameter1/parameter2 format.

                  Now, let me start coding.