How to get previous url in JSF using FacesContext?

I need to get the redirected URL or id in JSF using FacesContext . For the current url I use.

 String currentPage = FacesContext.getCurrentInstance().getViewRoot().getViewId(); 
+6
source share
1 answer

Closest you can get the referer via ExternalContext#getRequestHeaderMap() :

 String referrer = externalContext.getRequestHeaderMap().get("referer"); // ... 

It should be borne in mind that this is a value controlled by the client and, thus, can be completely faked on the client side (i.e., the end user can easily edit or even delete it).

Even then, there are times when the client application does not send it. For a review, see, Among other things, this question: In what cases will HTTP_REFERER be empty .

Depending on the functional requirement, you must manually pass it as a query parameter or store it in the field of view or session.

+11
source

Source: https://habr.com/ru/post/982015/


All Articles