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 URL / URI / domain URL / base URL


[OmniFaces utilities] The getRequestDomainURL() method returns the HTTP request domain URL. This is the URL with the scheme and domain, without any trailing slash.
[OmniFaces utilities] The getRequestBaseURL() method returns the HTTP request base URL. This is the URL from the scheme, domain until with context path, including the trailing slash. This is the value you could use in HTML <base> tag.
[OmniFaces utilities] The getRequestURL() method returns the HTTP request URL. This is the full request URL as the enduser sees in browser address bar. This does not include the request query string.
[OmniFaces utilities] The getRequestURI() method returns the HTTP request URI. This is the part after the domain in the request URL, including the leading slash. This does not include the request query string.

MethodFaces#getRequestDomainURL() returns the HTTP request domain URL

Method Faces#getRequestBaseURL() returns the HTTP request base URL

MethodFaces#getRequestURL() returns the HTTP request URL

Method Faces#getRequestURI() returns the HTTP request URI

Usage:

Let's suppose the following HTTP request (faces servlet mapping is a prefix mapping, /faces/*):

http://localhost:8080/MyApp/faces/index.xhtml

Further, let's apply the above methods, one by one, as follows:

·         get the HTTP request domain URL (Faces#getRequestDomainURL())
import org.omnifaces.util.Faces;
...
// returns http://localhost:8080
String requestDomainURL = Faces.getRequestDomainURL();

·         get the HTTP request base URL (Faces#getRequestBaseURL())
import org.omnifaces.util.Faces;
...
// returns http://localhost:8080/MyApp/
String requestBaseURL = Faces.getRequestBaseURL();

·         get the HTTP request URL (Faces#getRequestURL())
import org.omnifaces.util.Faces;
...
// returns http://localhost:8080/MyApp/faces/index.xhtml
String requestURL = Faces.getRequestURL();

·         get the HTTP request URI (Faces#getRequestURI())
import org.omnifaces.util.Faces;
...
// returns /MyApp/faces/index.xhtml
String requestURI = Faces.getRequestURI();

In the below figure, you can see these four methods and what they return:


Let's suppose the following HTTP request (faces servlet mapping is a suffix mapping, *.xhtml):

http://localhost:8080/MyApp/index.xhtml

Further, let's apply the above methods, one by one, as follows:

·         get the HTTP request domain URL (Faces#getRequestDomainURL())
import org.omnifaces.util.Faces;
...
// returns http://localhost:8080
String requestDomainURL = Faces.getRequestDomainURL();

·         get the HTTP request base URL (Faces#getRequestBaseURL())
import org.omnifaces.util.Faces;
...
// returns http://localhost:8080/MyApp/
String requestBaseURL = Faces.getRequestBaseURL();

·         get the HTTP request URL (Faces#getRequestURL())
import org.omnifaces.util.Faces;
...
// returns http://localhost:8080/MyApp/index.xhtml
String requestURL = Faces.getRequestURL();

·         get the HTTP request URI (Faces#getRequestURI())
import org.omnifaces.util.Faces;
...
// returns /MyApp/index.xhtml
String requestURI = Faces.getRequestURI();

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