Search code examples
jsfjsf-2url-encodinghttp-request-parameters

Missing character "+" in the return value of Request Parameter Map in JSF


I am trying to get parameters from an URL in my JSF application. The URL as following: http://localhost:8088/*******/pages/rh/evaluation/layouts/evaluationLayout.jsf?crt_affectId=RqI+dgtx6q8=

So here the parameter is crt_affectId and its value is RqI+dgtx6q8=. When I try to get the value by using the following code:

String cryptedValue = FacesContext.getCurrentInstance().getExternalContext()
    .getRequestParameterValuesMap().get(cryptedKey)[0];

I get the wanted value but missing the character + as it is replaced by a blank space as . the result value is as following: RqI dgtx6q8=.

Is there a solution in JSF to get the complete value or a should I just replace the blank space by the "+"? However this latter is not that generic and good way neither.


Solution

  • The + is URL-encoded representation of the space. So the behavior is correct. Those parameters should have been URL-encoded beforehand.

    If you have full control over those parameters, then you can URL-encode the individual parameter values as below before passing it to e.g. ExternalContext#redirect().

    String url = "/evaluationLayout.jsf?crt_affectId=" + URLEncoder.encode("RqI+dgtx6q8=", "UTF-8");
    ec.redirect(ec.getRequestContextPath() + url);
    

    In case you happen to use JSF utility library OmniFaces, it can be done more conveniently as its Faces#redirect() utility already transparently takes care of this.

    Faces.redirect("/evaluationLayout.jsf?crt_affectId=%s", "RqI+dgtx6q8=");
    

    See also: