Getting the original URI request with PrettyFaces

I am using PrettyFaces in my JSF application. The site requires authentication to access some pages, so I use a listener (prerender view) that checks if the user is logged in. That way, if the user tries to access / foo (/foo.jsf before PrettyFaces), I redirect to login.

However, I want to redirect them to my original address, so I want to add the "next" request parameter to redirect the user to / login instead? next = / foo. Unfortunately, I cannot get the original uri request from the request object, the uri string in the following code: /appname/foo.jsf instead of / appname / foo

ctx = FacesContext.getCurrentInstance().getExternalContext(); HttpServletRequest request = (HttpServletRequest) ctx.getRequest(); String uri = request.getRequestURI(); 

Is there any way to get the source path of the URI?

+7
source share
2 answers

PrettyFaces uses RequestDispatcher#forward() under the covers to redirect a pretty URL to a real URL. Using this technique, the source request URI is available as a request attribute with the key RequestDispatcher#FORWARD_REQUEST_URI .

So this should do:

 String originalURI = (String) externalContext.getRequestMap().get(RequestDispatcher.FORWARD_REQUEST_URI); // ... 
+6
source

Use this code to get the source URL of the request:

PrettyContext.getCurrentInstance (). GetRequestUrl (). ToURL ()

+3
source

All Articles