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.

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Elroy Jetson
  • 938
  • 11
  • 27
  • 1
    Try the [`getParameterMap()`](https://docs.oracle.com/javaee/6/api/javax/servlet/ServletRequest.html#getParameterMap()) method on the `request` object. Or you can also use the `getParameter(parmName)` method. – Bhesh Gurung Jun 04 '18 at 19:11
  • @BheshGurung Yeah, not sure how I missed this. Thanks/sorry. Write as an answer and I will accept. – Elroy Jetson Jun 04 '18 at 19:13
  • 1
    Way more easy solutions. Read: https://stackoverflow.com/questions/28780051/managedproperty-with-request-parameter-not-set-in-a-named-bean – Kukeltje Jun 04 '18 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. – Elroy Jetson Jun 04 '18 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: https://stackoverflow.com/questions/4888942/viewparam-vs-managedpropertyvalue-param-id where the @Param has additional features for validation etc... Cool thing! – Kukeltje Jun 04 '18 at 19:32
  • This job is meant to be done by the JSF framework.. – Aritz Jun 26 '18 at 12:01

1 Answers1

2

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

Bhesh Gurung
  • 50,430
  • 22
  • 93
  • 142