Reputation: 16525
My application is supporting more then language. Problem is when user logout (which means I call getSession().invalidate()
) then current language is lost and there is created new session with default language.
Language is sets via link:
add(new Link<Void>("goSk") {
private static final long serialVersionUID = 1L;
@Override
public void onClick() {
getSession().setLocale(new Locale("sk", "SK"));
}
});
add(new Link<Void>("goEn") {
private static final long serialVersionUID = 1L;
@Override
public void onClick() {
getSession().setLocale(Locale.US);
}
});
So question is how should I keep current language when I invaliate session
Upvotes: 1
Views: 385
Reputation: 4015
EDIT: invalidating session does not allow to reset a parameter in the session. a viable solution I successfully tested is to use PageParameters
Locale currentLocale=getSession().getLocale();
session.invalidate();//clear all session data
PageParameters pp=new PageParameters();
pp.add("locale", currentLocale.getLanguage());
setResponsePage(<you class>.class,pp);
and in the page you specified in setResponsePage you have to provide a constructor with PageParameters something like
public class Login extends BasePage {
public Login(PageParameters pp) {
//your code here
logger.debug("login user"+pp.getString("locale"));
}
Wicket passes the parameter via query string I tried this with a working test case
Upvotes: 1
Reputation: 17513
Better use a Cookie for anonymous users. Before invalidating save the lang in a cookie. In YourSession#getLocale() use the cookie if there is no user.
Upvotes: 4