DD.
DD.

Reputation: 21981

JSF Storing data into a cookie

I want to store some user data into a cookie so it's always there when they load the web app, even if the session has expired.

What's the best way of doing this with JSF?

Upvotes: 11

Views: 12664

Answers (1)

Brian
Brian

Reputation: 13571

Writing to a cookie:

FacesContext.getCurrentInstance()
 .getExternalContext()
 .addResponseCookie("CookieName", "value", null);

Reading the cookie

Map<String, Object> requestCookieMap = FacesContext.getCurrentInstance()
   .getExternalContext()
   .getRequestCookieMap();

Upvotes: 20

Related Questions