Elroy Jetson
Elroy Jetson

Reputation: 968

How can I get URL parameters in JSF

I can get the URL or URI just fine. However, JSF seems to exclude any URL parameters. For example:

Suppose the url is: www.example.com/pleasework?param=1

 import javax.servlet.http.HttpServletRequest;

 public String getUrl() {
   HttpServletRequest request = (HttpServletRequest) 
   FacesContext.getCurrentInstance().getExternalContext().getRequest();
   String url = request.getRequestURL().toString();
   String uri = request.getRequestURI();
   return uri;
 }

My result is everything up until the ? but I need everything after the ?

How can I accomplish this in JSF

Note: I need to get the URL server side so using Javascript's window.location.href and storing value in hidden field is not a solution for me because I need the parameters on page load.

Upvotes: 1

Views: 1491

Answers (1)

Bhesh Gurung
Bhesh Gurung

Reputation: 51030

Try the getParameterMap() method on the request object. Or you can also use the getParameter(parmName) method.

Upvotes: 2

Related Questions