Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package net.gvcc.jgoffice.system.factories; import com.vaadin.server.VaadinSession; import net.gvcc.jgoffice.searchcomponent.SearchComponent; /** * * @author ernst_sgv */ public class SearchBarFactory { private final static String SESSION_SCOPED_VALUE_ID = "sessionSearchComponent"; private SearchBarFactory() { } public static SearchComponent getInstance() { if (VaadinSession.getCurrent().getAttribute(SESSION_SCOPED_VALUE_ID) == null) { try { VaadinSession.getCurrent().lock(); VaadinSession.getCurrent().setAttribute(SESSION_SCOPED_VALUE_ID, new SearchComponent()); } finally { VaadinSession.getCurrent().unlock(); } } return (SearchComponent) VaadinSession.getCurrent().getAttribute(SESSION_SCOPED_VALUE_ID); } }