Jonathan S. Fisher
Jonathan S. Fisher

Reputation: 8817

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

Upvotes: 4

Views: 2502

Answers (1)

Lincoln
Lincoln

Reputation: 3191

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

Upvotes: 7

Related Questions