0

I'm using tuckey URL rewriting with JSF.

I would like to get the relative URL including parameters that the user sees: e.g.

example.com/mypage?param=test

At the moment if I do

#{view.viewId}

I get

mypage.xhtml

what I want to get is:

mypage?param=test

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
DD.
  • 21,498
  • 52
  • 157
  • 246

1 Answers1

3

The UIViewRoot#getViewId() returns the JSF view ID. You need to use HttpServletRequest#getRequestURI() to obtain the current request URI and HttpServletRequest#getQueryString() to obtain the current request query string.

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

Or, if it's a forwarded request, get it as a request attribute keyed with 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']}

Clumsy yes. Consider hiding away in <c:set> of a master template, or an utility tag/function.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • This doesnt work...it shows mypage.xhtml?param=test, I want to display the rewritten URL mypage?param=test – DD. Oct 22 '15 at 12:34