My JSF Books/Videos My JSF Tutorials OmniFaces/JSF PPTs
JSF 2.3 Tutorial
JSF Caching Tutorial
JSF Navigation Tutorial
JSF Scopes Tutorial
JSF Page Author Beginner's Guide
OmniFaces 2.3 Tutorial Examples
OmniFaces 2.2 Tutorial Examples
JSF Events Tutorial
OmniFaces Callbacks Usages
JSF State Tutorial
JSF and Design Patterns
JSF 2.3 New Features (2.3-m04)
Introduction to OmniFaces
25+ Reasons to use OmniFaces in JSF
OmniFaces Validators
OmniFaces Converters
JSF Design Patterns
Mastering OmniFaces
Reusable and less-verbose JSF code

My JSF Resources ...

Java EE Guardian
Member of JCG Program
Member MVB DZone
Blog curated on ZEEF
OmniFaces is an utility library for JSF, including PrimeFaces, RichFaces, ICEfaces ...

.

.

.

.

.

.

.

.


[OmniFaces Utilities] - Find the right JSF OmniFaces 2 utilities methods/functions

Search on blog

Petition by Java EE Guardians

Twitter

joi, 26 martie 2015

[OmniFaces utilities (2.0)] Get HTTP request query string as String and Map / URL with query string / URI with query string


[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.

MethodFaces#getRequestQueryString() return HTTP request query string

MethodFaces#getRequestQueryStringMap() return HTTP request query string as parameter values map

MethodFaces#getRequestURLWithQueryString() return HTTP request URL with query string

MethodFaces#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:

Niciun comentariu :

Trimiteți un comentariu

JSF BOOKS COLLECTION

Postări populare

OmniFaces/JSF Fans

Visitors Starting 4 September 2015

Locations of Site Visitors