package com.mousetech.gourmetj; import java.io.Serializable; import javax.enterprise.context.SessionScoped; import javax.inject.Named; import org.primefaces.PrimeFaces; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.mousetech.gourmetj.persistence.model.Category; import com.mousetech.gourmetj.persistence.model.Recipe; import com.mousetech.gourmetj.utils.TimeFormatter; @Named @SessionScoped public class UserSession implements Serializable { /** * Serial version for session save/restore */ private static final long serialVersionUID = 7449440266704831598L; /* Logger */ private static final Logger log = LoggerFactory.getLogger(UserSession.class); private String lastSearch = ""; /** * @return the lastSearch */ public String getLastSearch() { return lastSearch; } /** * @param lastSearch the lastSearch to set */ public void setLastSearch(String lastSearch) { this.lastSearch = lastSearch; } private Long lastEdit; /** * @return the lastEdit */ public Long getLastEdit() { return lastEdit; } /** * @param lastEdit the lastEdit to set */ public void setLastEdit(Long lastEdit) { this.lastEdit = lastEdit; } // *** /** * Tab index to select when presenting editDetails. First tab * is 0. */ private int detailTab; /** * @return the detailTab */ public int getDetailTab() { return detailTab; } /** * @param detailTab the detailTab to set */ public void setDetailTab(int detailTab) { this.detailTab = detailTab; } // *** private Recipe recipe; /** * Recipe is set by the mainpage bean to a blank recipe * before dispatching to the detailEdit page (new recipe). It * is also set by the detail view page so that the detail * view can be edited. * * In addition to detail editing, it's also used by the * * @see PictureController. * * @return Recipe selected. */ public Recipe getRecipe() { return recipe; } /** * @param recipe the recipe to set */ public void setRecipe(Recipe recipe) { this.recipe = recipe; } // ==== public String formatCategories(Recipe r) { StringBuffer sb = new StringBuffer(30); boolean first = true; for (Category cat : r.getCategories()) { if (first) { first = false; } else { sb.append(", "); } sb.append(cat.getCategory()); } return sb.toString(); } //** Util, consider conversion to JSF Converter public String formatTime(Long ltime) { return TimeFormatter.formatTime(ltime); } // Primefaces handle session timeout // Session timeout, ms long sessionTimeoutInterval = 30000L; /** * @return the sessionTimeoutInterval */ public long getSessionTimeoutInterval() { return sessionTimeoutInterval; } public void sessionIdleListener() { log.warn("Session Idle Listener fired."); PrimeFaces.current() .executeScript("sessionExpiredConfirmation.show()"); } public String logoutAction() { log.warn("Session Idle listener logout"); return "/main.jsf"; } }