Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get previous URL in JSF using FacesContext?

Tags:

jsf

jsf-2.2

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();
like image 419
Lavanya Avatar asked Feb 05 '15 05:02

Lavanya


1 Answers

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.

like image 84
BalusC Avatar answered Oct 22 '22 03:10

BalusC