I need to do very simple thing – pass current URL from JSF (2.0) page to the managed bean. This is needed to get URL of the login form which will redirect user back to the current page after login. (I use GAE and the bean is the wrapping around its user service, if it does matter). Any obvious way I tried doesn’t work
<c:set /> – doesn’t work (w/o any error or warning message)
getter which takes current URL as a parameter – doesn’t work.
So many questions and many recipes, but all are complex and not elegant. Why? May be I (as other who asking) missed a key design principle? I’ll appreciate any answer – simple and straightforward recipe or explanation why not to do so.
I need to do very simple thing – pass current URL from JSF (2.0)
Share
It’s available by
#{request.requestURL}(or if you only want the domain-relative path, use#{request.requestURI}). Usef:paramto pass it and@ManagedPropertyto handle it.with
Noted should be that
f:paraminside ah:commandButtondoesn’t work in JSF 1.x. You’d like to useh:commandLinkinstead.Update as per the comments: I understood that you wanted to “pass current URL to the managed bean”. But you actually want to “access current URL in managed bean”.
In that case, either replace
#{param.url}by#{request.requestURL}:Or obtain the raw
HttpServletRequestinstance from under the JSF hoods byExternalContext#getRequest():