Search code examples
httprequestvaadinhttpsession

vaadin access session attribute that was put in filter


I've got multiple filters. In one of the filters I've got this code

HttpServletRequest request = (HttpServletRequest) req;
String url = request.getRequestURI();

HttpSession session = request.getSession();
if (request.getParameter("xxxx") != null)
    session.setAttribute("xxxx", request.getParameter("xxxx"));
chain.doFilter(req, res);

For UI I use VAADIN 7. And I decided to display the value of the parameter xxxx in the table. So I wanted to do it like this

Table table = new Table("Data.");
table.setSizeFull();
table.addContainerProperty("Field", String.class, null);
table.addContainerProperty("Value", String.class, null);
table.setStyleName("wordwrap-table");
table.setStyleName("user-table");

Object attribute = VaadinSession.getCurrent().getAttribute("xxxx");

However attribute value is null. Why? And how to resolve this problem?


Solution

  • You need another getSession() in there:

    Object attribute = VaadinSession.getCurrent().getSession().getAttribute("xxxx");
    

    The result of VaadinSession.getCurrent() is the current Vaadin Session. The next getSession() gets you the HTTP session, which is where your attributes live.