Get rewritten URL with query string

I am using rewrite urls using JSF.

I would like to get a relative URL, including parameters that the user sees: for example.

example.com/mypage?param=test 

At the moment, if I do

 #{view.viewId} 

I get

mypage.xhtml

what i want to get:

MyPage? Pairs = Test

0
query-string url-rewriting jsf jsf-2
source share
1 answer

UIViewRoot#getViewId() returns a JSF view identifier. You need to use HttpServletRequest#getRequestURI() to get the current request URI and HttpServletRequest#getQueryString() to get the current request string.

 #{request.requestURI}#{empty request.queryString ? '' : '?'}#{request.queryString} 

Or, if it is a redirected request, get it as a request attribute with the RequestDispatcher.FORWARD_REQUEST_URI and RequestDispatcher.FORWARD_QUERY_STRING respectively:

 #{requestScope['javax.servlet.forward.request_uri']}#{empty requestScope['javax.servlet.forward.query_string'] ? '' : '?'}#{requestScope['javax.servlet.forward.query_string']} 

Awkward yes. Consider hiding the main template or service tag / function in <c:set> .

+3
source share

All Articles