Search code examples
javajakarta-eejsf-2url-rewritingprettyfaces

JSF2 and PrettyFaces... how does one get the original URL or the query string?


PrettyFaces is a dead simple URL rewriting engine. All sorts of SEO is possible and it is really really easy. I have one small problem though :(

Using pretty faces, I have this rewrite rule:

<url-mapping id="blogEntry">
    <pattern value="/blog/#{shortUrl}" />
    <view-id value="/blogEntry.jsf" />
</url-mapping>

So the URL bar looks like:

http://host.com/blog/first-post

And the rewrite rule maps the request internally to:

http://host.com/blogEntry?shortUrl=first-post

I'm implementing OpenID, which means I need to give the OpenID provider a return-to URL. However, when I do the following:

originalUrl = Faces.getRequest().getRequestURL().toString()

I get:

http://host.com/blogEntry.jsf

getQueryString() returns an empty string

Anyone know of way to either get the purty URL: http://host.com/blog/first-post or at minimum the query string shortUrl=first-post


Solution

  • You can use: PrettyContext.getCurrentInstance().getRequestUrl().toURL() and PrettyContext.getCurrentInstance().getRequestQueryString().toQueryString()

    Similar forum post: http://ocpsoft.org/support/topic/how-get-the-original-request-uri-from-jsf