How i can change the Expired Session Message ?

hello I do not speak English very well, I want to change to my language the expired session message , how i can do this ?

“Override” [1]
the Application #getSystemMessages method. See
Section 4.7.3
of the Book of Vaadin for more details.

Cheers,

Charles.

[1]
It’s a static method, so it’s not really “overriding” - but much the same idea. Vaadin will call the method on your application class if it is there.

That’s pretty easy idea, but how to deal when you’ve got few different localizations in application and they depends on logged user? There is problem that this method is static…

Regards,
Kuba

You could create something that used a ThreadLocal to get the user’s locale.

There, the problem is that at least some of these system error messages need to go to the client before the user is logged on and the application gets information about locale etc. from the browser, and some of them (like session expired) will be used when there is no longer a session on the server so no way of asking the server for more information.

See the related ticket
#8376
.

EDIT: See also
#4127
and especially
#9869
- there is hope of getting this done for most cases, currently targeting Vaadin 7.1.

Oops : makes sense…

Hello all,

I have a question regarding this topic. As Henri wrote above the system error messages have to be available before the use ris logged on. Is now (4 years later ;-)) a way to set the messages depending of the suer which has logged-on (different language)?

Best Regards,
Thomas

Here is my code:

(1)create a class to get SystemMessages from resource file:

public class SpringSystemMessagesProvider implements SystemMessagesProvider {
    private MessageSource messageSource;

    private void loadMessageSource() {
        if (this.messageSource == null) {
            this.messageSource = // ... get MessageSource bean from Spring context ...
        }
    }

    @Override
    public SystemMessages getSystemMessages(final SystemMessagesInfo systemMessagesInfo) {
        this.loadMessageSource();

        Locale locale = systemMessagesInfo.getLocale();

        CustomizedSystemMessages systemMessages = new CustomizedSystemMessages();

        // =====================================================================
        // Vaadin.SessionExpired
        String message = this.messageSource.getMessage("Vaadin.SessionExpired.URL", null, locale);
        if (StringUtils.isNotEmpty(message)) {
            systemMessages.setSessionExpiredURL(message);
        }
        
        // .... and you can get the other messages from resource file .....

        
        return systemMessages;
    }
}

(2)use our customized SystemMessagesProvider:

@WebServlet(value = "/*", asyncSupported = true)
public static class Servlet extends SpringVaadinServlet {
    @Override
    protected VaadinServletService createServletService(final DeploymentConfiguration deploymentConfiguration)
            throws ServiceException {
        VaadinServletService service = super.createServletService(deploymentConfiguration);

        SystemMessagesProvider msgProvider = new SpringSystemMessagesProvider();
        service.setSystemMessagesProvider(msgProvider);

        return service;
    }
}

For more information, you can read the “Customizing System Messages” section here:
https://vaadin.com/docs/-/part/framework/application/application-errors.html

Perfect!! Thanks a lot!