8

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();
Tiny
  • 27,221
  • 105
  • 339
  • 599
Lavanya
  • 89
  • 1
  • 10

1 Answers1

18

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.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks., I got the full url. in the getViewId() i will get the current page name like "login.xhtml". I need like that. is there other code to get like that. – Lavanya Feb 06 '15 at 09:17
  • Thanks, I ll delimit the url and proceed. – Lavanya Feb 06 '15 at 09:46