Question

What is the best way of saving preferences on client side (eg. language choice) for a JSF WebApp? I would like the data to persist the closing of the browser. Per requirement I can't use the browser locale to detect the preferred language.

I was hoping for something like a BrowserScoped bean. Should I try using a CustomScoped bean (I've never used them before) or should I use plain old JavaScript?

Thanks!

Was it helpful?

Solution

Sounds like you're looking for long living Cookies to me.

You should take a look at ExternalContext.addResponseCookie() to store your cookie and HttpServletRequest.getCookies() to retrieve it.
Although it's not the same use case as yours I would like to refer you to this BalusC answer if you want grant your cookies a long life.

OTHER TIPS

I recommend an approach involving JavaScript DOM Storage. You can tie it to a session if necessary. It boils down to a map of properties at its core, that is accessible from your app's domain.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top