1

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.

6
  • 1
    Try the getParameterMap() method on the request object. Or you can also use the getParameter(parmName) method. Commented Jun 4, 2018 at 19:11
  • @BheshGurung Yeah, not sure how I missed this. Thanks/sorry. Write as an answer and I will accept. Commented Jun 4, 2018 at 19:13
  • 1
    Way more easy solutions. Read: stackoverflow.com/questions/28780051/… Commented Jun 4, 2018 at 19:22
  • @Kukeltje thanks for the contribution; however I believe that the solution you're referencing applies to @RequestScope bean. My bean is @SessionScoped and this would not be a solution for me, but perhaps will be for someone else. Commented Jun 4, 2018 at 19:25
  • 2
    @Named with @Param works in sessionscoped beans as well (you did not mention SessionScoped) And for 'page load' there are other solutions too where it is explicit in the page that it is for pageloading: stackoverflow.com/questions/4888942/… where the @Param has additional features for validation etc... Cool thing! Commented Jun 4, 2018 at 19:32

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.