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

vineri, 19 iunie 2015

[OmniFaces utilities (2.1)] Add a cookie with given name, value, path, domain and maxage to the HTTP response


Because Google Chrome doesn't like domain: "localhost" on cookies, OmniFaces adapted this method in version 2.1 to skip setting cookie domain when it equals "localhost". This is still available in vesion 2.0.

[OmniFaces utilities] The addResponseCookie() method add a cookie with given name, value, path and maxage to the HTTP response. The cookie value will implicitly be URL-encoded with UTF-8 so that any special characters can be stored in the cookie. The cookie will implicitly be set to secure when the current request is secure (i.e. when the current request is a HTTPS request). The cookie will implicitly be set in the domain and path of the current request URL.

Note I: The maxAge argument represents the maximum age of the cookie, in seconds. If this is 0, then the cookie will be removed. Note that the name and path must be exactly the same as it was when the cookie was created. If this is -1 then the cookie will become a session cookie and thus live as long as the established HTTP session.
Note II: The path argument represents the cookie path. If this is /, then the cookie is available in all pages of the webapp. If this is /somespecificpath, then the cookie is only available in pages under the specified path.
Note III: The domain argument represents cookie domain. You can use .example.com (with a leading period) if you'd like the cookie to be available to all subdomains of the domain. Note that you cannot set it to a different domain.

Method Faces#addResponseCookie() - add a cookie with given name, value and maxage to the HTTP response


Method Faces#addResponseCookie() - add a cookie with given name, value path and maxage to the HTTP response


Method Faces#addResponseCookie() - add a cookie with given name, value, path, domain and maxage to the HTTP response

Usage:

Add a cookie with given name, value and maxage to the HTTP response

import org.omnifaces.util.Faces;
...
// cookie will be removed
Faces.addResponseCookie("favorite_game", "Time Gap", 0);

// cookie will expire after 15 seconds
Faces.addResponseCookie("favorite_game", "Time Gap", 15);

// session cookie
Faces.addResponseCookie("favorite_game", "Time Gap", -1);

Add a cookie with given name, value, path and maxage to the HTTP response.

import org.omnifaces.util.Faces;
...
// session cookie with explicit path
Faces.addResponseCookie("favorite_game", "Time Gap", "/mypath", -1);


Add a cookie with given name, value, domain, path and maxage to the HTTP response.

import org.omnifaces.util.Faces;
...
// session cookie with explicit path and domain
Faces.addResponseCookie("favorite_game", "Time Gap", ".mydomain.com","/mypath", -1);


// setting 'localhost' as domain is taken into account in OmniFaces 2.0, but not in 2.1
Faces.addResponseCookie("favorite_game", "Time Gap", "localhost","/mypath", -1);

The cookie will implicitly be set to secure when the current request is secure (i.e. when the current request is a HTTPS request):

Niciun comentariu :

Trimiteți un comentariu

JSF BOOKS COLLECTION

Postări populare

OmniFaces/JSF Fans

Visitors Starting 4 September 2015

Locations of Site Visitors