Get a session locale string in JPQL

I tried this where clause to no effect (it complains the tostring function does not exist):

where function('toString', :session$locale) = e.localization

btw e.localization is a locale 2 char string

Is there a way?

Hi Lucio,

I suppose you are writing JPQL for a screen datasource.

First of all, there is no such parameter as session$locale. Please see the docs where explained that the value of a parameter with the session$ prefix is obtained by the UserSession.getAttribute() method. It means that you have to put the parameter to the session beforehand using the UserSession.setAttribute() method.

For you task, you can do it in an event listener for the UserSessionStartedEvent event, see web login events. Something like this:

protected void onUserSessionStarted(UserSessionStartedEvent event) {
    event.getUserSession().setAttribute("locale", event.getUserSession().getLocale());
1 Like