Glory to Russia
Glory to Russia

Reputation: 18760

Unique identifier for every user/session in JSF

I have a JSF application and want to assign to every user, who opens it in the browser, a unique identifier.

To implement it, I want to use a global long variable and increment it, whenever a new user connects to the web application.

I have 2 questions:

1) Where (in which method) should I place the increment code?

2) How can I access that global variable in Java classes of the web app?

Upvotes: 0

Views: 782

Answers (1)

Steve Atkinson
Steve Atkinson

Reputation: 1239

You already have a session id assigned for free by the appServer. To get at it in your bean code:

ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
HttpSession session = (HttpSession) ec.getSession(false);
String sessionId = session.getId();

Upvotes: 5

Related Questions