Reputation: 89
I need to get the redirected URL or id in JSF using FacesContext
. For current URL, I'm using.
String currentPage = FacesContext.getCurrentInstance().getViewRoot().getViewId();
Upvotes: 8
Views: 7741
Reputation: 1109865
Closest you can get is the referer
header via ExternalContext#getRequestHeaderMap()
:
String referrer = externalContext.getRequestHeaderMap().get("referer");
// ...
You should only keep in mind that this is a client-controlled value and can thus be fully spoofed from client side on (i.e. the enduser can easily edit or even remove it).
Even then, there are cases where the client application won't send it along. For an overview, see among others this question: In what cases will HTTP_REFERER be empty.
Depending on the functional requirement, you'd better manually pass it along as request parameter, or store it in view or session scope.
Upvotes: 18