[OmniFaces utilities] The
getRequestQueryString()
method returns the HTTP request query string. This is the part after the
?
in the request URL as the enduser sees in browser address bar.
[OmniFaces utilities] The
getRequestQueryStringMap()
method returns the HTTP request query string as parameter values map. Note this method returns
only the request URL (GET) parameters, as opposed to
getRequestParameterValuesMap()
, which contains both the request URL (GET) parameters and and the request body (POST) parameters. This is ready for usage in among others
ViewHandler#getBookmarkableURL(FacesContext, String, Map, boolean)
.
[OmniFaces utilities] The
getRequestURLWithQueryString()
method returns the HTTP request URL with query string. This is the full request URL with query string as the enduser sees in browser address bar.
[OmniFaces utilities] The
getRequestURIWithQueryString()
method returns the HTTP request URI with query string. This is the part after the domain in the request URL, including the leading slash and the request query string.
Method -
Faces#getRequestQueryString() return HTTP request query string
Method -
Faces#getRequestQueryStringMap() return HTTP request query string as parameter values map
Method -
Faces#getRequestURLWithQueryString() return HTTP request URL with query string
Method -
Faces#getRequestURIWithQueryString() return HTTP request URI with query string
Usage:
Let's suppose the following JSF-HTTP request
(faces servlet mapping is a prefix mapping, /faces/*):
http://localhost:8080/MyApp/faces/index.xhtml?name=Rafael&surname=Nadal&age=27&rank=1
Further,
let's apply the above methods, one by one, as follows:
·
get the HTTP request query string (Faces#getRequestQueryString())
- if query string is missing, returns null
import
org.omnifaces.util.Faces;
...
// returns name=Rafael&surname=Nadal&age=27&rank=1
String requestQueryString =
Faces.getRequestQueryString();
·
get the HTTP request query string as parameter
values map (Faces#getRequestQueryStringMap())
import
org.omnifaces.util.Faces;
...
// prints name#[Rafael], surname#[Nadal], age#[27], rank#[1]
Map<String,
List<String>> requestQueryStringMap =
Faces.getRequestQueryStringMap();
for
(Map.Entry<String, List<String>> entry : requestQueryStringMap.entrySet())
{
System.out.println(entry.getKey() +
"#" + entry.getValue());
// do something with request parameters
}
·
get the HTTP request URL with query string (Faces#getRequestURLWithQueryString())
import
org.omnifaces.util.Faces;
...
// returns http://localhost:8080/MyApp/faces/index.xhtml?name=Rafael&surname=Nadal&age=27&rank=1
String requestURLWithQueryString
= Faces.getRequestURLWithQueryString();
·
get the HTTP request URI with query string (Faces#getRequestURIWithQueryString())
import
org.omnifaces.util.Faces;
...
// returns /MyApp/faces/index.xhtml?name=Rafael&surname=Nadal&age=27&rank=1
String requestURIWithQueryString
= Faces.getRequestURIWithQueryString();
In the below
figure, you can see these four methods and what they return:
Let's suppose the following JSF-HTTP request
(faces servlet mapping is a suffix mapping, *.xhtml):
http://localhost:8080/MyApp/index.xhtml?name=Rafael&surname=Nadal&age=27&rank=1
Further,
let's apply the above methods, one by one, as follows:
·
get the HTTP request query string (Faces#getRequestQueryString())
- if query string is missing, returns null
import
org.omnifaces.util.Faces;
...
// returns name=Rafael&surname=Nadal&age=27&rank=1
String requestQueryString =
Faces.getRequestQueryString();
·
get the HTTP request query string as parameter
values map (Faces#getRequestQueryStringMap())
import
org.omnifaces.util.Faces;
...
// prints name#[Rafael], surname#[Nadal], age#[27], rank#[1]
Map<String,
List<String>> requestQueryStringMap =
Faces.getRequestQueryStringMap();
for
(Map.Entry<String, List<String>> entry : requestQueryStringMap.entrySet())
{
System.out.println(entry.getKey() +
"#" + entry.getValue());
// do something with request parameters
}
·
get the HTTP request URL with query string (Faces#getRequestURLWithQueryString())
import
org.omnifaces.util.Faces;
...
// returns http://localhost:8080/MyApp/index.xhtml?name=Rafael&surname=Nadal&age=27&rank=1
String requestURLWithQueryString
= Faces.getRequestURLWithQueryString();
·
get the HTTP request URI with query string (Faces#getRequestURIWithQueryString())
import
org.omnifaces.util.Faces;
...
// returns /MyApp/index.xhtml?name=Rafael&surname=Nadal&age=27&rank=1
String requestURIWithQueryString
= Faces.getRequestURIWithQueryString();
In the below
figure, you can see these four methods and what they return: