Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is the 'cookie' global object supposed to work on xPages?

Tags:

xpages

How is the 'cookie' global object supposed to work on xPages? It is a map, so I can check the cookie existence easily, but how to create a new cookie? Using cookie.name="value" raises an error because, as supposed, the cookie must be some object with params like expiration etc. But what kind of the object it is? I can't find any suitable documentation for this or I miss something.

like image 960
David Marko Avatar asked Feb 20 '23 11:02

David Marko


1 Answers

cookie object represents a map of cookie values of the request instance. So you cannot use it because 'setting cookie' means 'adding cookie to the response'.

So, as the article suggests, you have to use response object.

var response = facesContext.getExternalContext().getResponse(); 
var userCookie = new javax.servlet.http.Cookie("name", "value"); 
userCookie.setMaxAge(60*60*24*365*10); // set age in seconds...
userCookie.setPath("/"); // cookie will be valid under this path
response.addCookie(userCookie);
like image 60
Serdar Basegmez Avatar answered Mar 03 '23 12:03

Serdar Basegmez