Vaadin 10 or 11 Application with session implementation

Hi,
I am pretty new to coding and vaadin,I am trying to buila a web application which will be used by 40 users,I am not getting how to implement vaadin session for the web application.Any sample application with vaadin 10/11 with session implementation will be useful.

I’m not sure if this is what you are looking for:

@WebServlet(urlPatterns = "/*", name = "UIServlet", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, heartbeatInterval = 20)
public class MyServlet extends CdiVaadinServlet implements SessionInitListener, SessionDestroyListener {

    private static final Logger LOGGER = LoggerFactory.getLogger(MyServlet.class);

    @Override
    protected void servletInitialized() throws ServletException {
        super.servletInitialized();
        getService().addSessionInitListener(this);
        getService().addSessionDestroyListener(this);
    }

    @Override
    public void sessionInit(SessionInitEvent event) throws ServiceException {
        LOGGER.info("session init() "
                + " Session-ID: " + event.getSession().getSession().getId()
                + " CSRF: " + event.getSession().getCsrfToken()
        );
    }

    @Override
    public void sessionDestroy(SessionDestroyEvent event) {
        LOGGER.info("session destroy()");
    }
}

This is some what close,how can i implement it inside a vaadin 10/11 application i.e say bakery application

I not sure, but the bakery used spring. For this example you need the CDI AddOn https://vaadin.com/directory/component/vaadin-cdi

Just create a class and copy the code. With this you override the default servlet.

So,we cant add session to bakery application?

You can, but in a other way.

I think you should ask a different question.

What you want to do with the session?

i want to store user details and other information during active session of a user.

Do you want to use spring, JEE or nothing?

With JEE you can use the example above.

With spring, maybe this: https://vaadin.com/docs/v10/flow/spring/tutorial-spring-basic-mvc.html

Without spring/JEE I guess this would be the right way: https://vaadin.com/docs/v10/flow/advanced/tutorial-flow-runtime-configuration.html

Then implement SessionInitListener and SessionDestroyListener.

I want to use spring and JEE

deekshith gowda:
I want to use spring and JEE

Usually you choose one of them. In some cases you can use parts from the other. But to use both would by unwise - maybe impossible, I don’t know.

My advice would be to read more about the two frameworks and the differences of them.

Or you just choose one of them. The concepts are similar.