Refine search
@Override public Object getSessionMutex() { // Enforce presence of a session first to allow listeners to create the mutex attribute ExternalContext externalContext = getExternalContext(); Object session = externalContext.getSession(true); Object mutex = externalContext.getSessionMap().get(WebUtils.SESSION_MUTEX_ATTRIBUTE); if (mutex == null) { mutex = (session != null ? session : externalContext); } return mutex; }
/** * Return the best available mutex for the given session: * that is, an object to synchronize on for the given session. * <p>Returns the session mutex attribute if available; usually, * this means that the HttpSessionMutexListener needs to be defined * in {@code web.xml}. Falls back to the Session reference itself * if no mutex attribute found. * <p>The session mutex is guaranteed to be the same object during * the entire lifetime of the session, available under the key defined * by the {@code SESSION_MUTEX_ATTRIBUTE} constant. It serves as a * safe reference to synchronize on for locking on the current session. * <p>In many cases, the Session reference itself is a safe mutex * as well, since it will always be the same object reference for the * same active logical session. However, this is not guaranteed across * different servlet containers; the only 100% safe way is a session mutex. * @param fc the FacesContext to find the session mutex for * @return the mutex object (never {@code null}) * @see org.springframework.web.util.WebUtils#SESSION_MUTEX_ATTRIBUTE * @see org.springframework.web.util.HttpSessionMutexListener */ @Nullable public static Object getSessionMutex(FacesContext fc) { Assert.notNull(fc, "FacesContext must not be null"); ExternalContext ec = fc.getExternalContext(); Object mutex = ec.getSessionMap().get(WebUtils.SESSION_MUTEX_ATTRIBUTE); if (mutex == null) { mutex = ec.getSession(true); } return mutex; }
/** * Removes the multiViewState for all DataLists within the current session. */ public void clearDataListStates() { getFacesContext().getExternalContext().getSessionMap().remove(Constants.DATALIST_STATE); }
public DataListState getDataListState(boolean create) { FacesContext fc = getFacesContext(); Map<String, Object> sessionMap = fc.getExternalContext().getSessionMap(); Map<String, DataListState> dlState = (Map) sessionMap.get(Constants.DATALIST_STATE); String viewId = fc.getViewRoot().getViewId().replaceFirst("^/*", ""); String stateKey = viewId + "_" + getClientId(fc); if (dlState == null) { dlState = new HashMap<>(); sessionMap.put(Constants.DATALIST_STATE, dlState); } DataListState ls = dlState.get(stateKey); if (ls == null && create) { ls = new DataListState(); dlState.put(stateKey, ls); } return ls; }
protected void handleRedirect(FacesContext context, Throwable rootCause, ExceptionInfo info, boolean responseResetted) throws IOException { ExternalContext externalContext = context.getExternalContext(); externalContext.getSessionMap().put(ExceptionInfo.ATTRIBUTE_NAME, info);
private static Set<String> getEditableWindowIdSet(ExternalContext externalContext) { Map<String, Object> sessionMap = externalContext.getSessionMap(); @SuppressWarnings({"unchecked"}) Set<String> existingWindowIdSet = (Set)sessionMap.get(EXISTING_WINDOW_ID_SET_KEY); if(existingWindowIdSet == null) { existingWindowIdSet = new HashSet<String>(); sessionMap.put(EXISTING_WINDOW_ID_SET_KEY, existingWindowIdSet); } return existingWindowIdSet; }
public void put(FacesContext facesContext, ExternalContext extContext, String name, Object obj) { extContext.getSessionMap().put(name, obj); } });
public TableState getTableState(boolean create) { FacesContext fc = getFacesContext(); Map<String, Object> sessionMap = fc.getExternalContext().getSessionMap(); Map<String, TableState> dtState = (Map) sessionMap.get(Constants.TABLE_STATE); String viewId = fc.getViewRoot().getViewId().replaceFirst("^/*", ""); String stateKey = viewId + "_" + getClientId(fc); if (dtState == null) { dtState = new HashMap<>(); sessionMap.put(Constants.TABLE_STATE, dtState); } TableState ts = dtState.get(stateKey); if (ts == null && create) { ts = new TableState(); dtState.put(stateKey, ts); } return ts; }
/** * Removes the multiViewState for one specific DataTable within the current session. * @param key Key of the DataTable. See {@link org.primefaces.component.datatable.DataTable#getTableState(boolean)} for the namebuild of this key. */ public void clearTableState(String key) { Map<String, Object> sessionMap = getFacesContext().getExternalContext().getSessionMap(); Map<String, TableState> dtState = (Map) sessionMap.get(Constants.TABLE_STATE); if (dtState != null) { dtState.remove(key); } }
@Override public void setSessionAttribute(FacesContext facesContext, String name, Object value) { ExternalContext externalContext = facesContext.getExternalContext(); Map<String, Object> sessionMap = externalContext.getSessionMap(); sessionMap.put(name, value); }
private static Set<String> getEditableWindowIdSet(ExternalContext externalContext) { Map<String, Object> sessionMap = externalContext.getSessionMap(); @SuppressWarnings({"unchecked"}) Set<String> existingWindowIdSet = (Set)sessionMap.get(EXISTING_WINDOW_ID_SET_KEY); if(existingWindowIdSet == null) { existingWindowIdSet = new HashSet<String>(); sessionMap.put(EXISTING_WINDOW_ID_SET_KEY, existingWindowIdSet); } return existingWindowIdSet; }
public void put(FacesContext facesContext, ExternalContext extContext, String name, Object obj) { extContext.getSessionMap().put(name, obj); } });
@Override public Object getSessionMutex() { // Enforce presence of a session first to allow listeners to create the mutex attribute ExternalContext externalContext = getExternalContext(); Object session = externalContext.getSession(true); Object mutex = externalContext.getSessionMap().get(WebUtils.SESSION_MUTEX_ATTRIBUTE); if (mutex == null) { mutex = (session != null ? session : externalContext); } return mutex; }
/** * Removes the multiViewState for all DataTables within the current session. */ public void clearTableStates() { getFacesContext().getExternalContext().getSessionMap().remove(Constants.TABLE_STATE); }
/** * Close the current dynamic dialog. * * @param data optional data to pass back to a dialogReturn event. */ public void closeDynamic(Object data) { FacesContext facesContext = getFacesContext(); Map<String, String> params = facesContext.getExternalContext().getRequestParameterMap(); String pfdlgcid = params.get(Constants.DIALOG_FRAMEWORK.CONVERSATION_PARAM); if (data != null) { Map<String, Object> session = facesContext.getExternalContext().getSessionMap(); session.put(pfdlgcid, data); } executeScript("PrimeFaces.closeDialog({pfdlgcid:'" + EscapeUtils.forJavaScript(pfdlgcid) + "'});"); }
/** * Removes the multiViewState for one specific DataList within the current session. * @param key Key of the DataList. See {@link org.primefaces.component.datalist.DataList#getDataListState(boolean)}} for the namebuild of this key. */ public void clearDataListState(String key) { Map<String, Object> sessionMap = getFacesContext().getExternalContext().getSessionMap(); Map<String, TableState> dtState = (Map) sessionMap.get(Constants.DATALIST_STATE); if (dtState != null) { dtState.remove(key); } }
private void forceAjaxOnView(FacesContext facesContext) { //ideally we would force this only for certain views //unfortunately the JSF view determinateion logic is not exposed //so we can only enable for a given session //Once the FileEntry component is used, all subsequent multipart //posts will have "Faces-Request: partial/ajax" set ExternalContext externalContext = facesContext.getExternalContext(); Map sessionMap = externalContext.getSessionMap(); sessionMap.put(AJAX_FORCED_VIEWS, AJAX_FORCED_VIEWS); } }
private static Set<String> getEditableWindowIdSet(ExternalContext externalContext) { Map<String, Object> sessionMap = externalContext.getSessionMap(); @SuppressWarnings({"unchecked"}) Set<String> existingWindowIdSet = (Set)sessionMap.get(EXISTING_WINDOW_ID_SET_KEY); if(existingWindowIdSet == null) { existingWindowIdSet = new HashSet<String>(); sessionMap.put(EXISTING_WINDOW_ID_SET_KEY, existingWindowIdSet); } return existingWindowIdSet; }
public void put(ExternalContext extContext, String name, Object obj) { extContext.getSessionMap().put(name, obj); } });
protected void afterResponseComplete(FacesContext facesContext) { //responseComplete() was called by one of the other phases, //so we will never get to the RENDER_RESPONSE phase //Note: we can't call Manager.instance().beforeRedirect() here, //since a redirect is not the only reason for a responseComplete ExternalContext externalContext = facesContext.getExternalContext(); Manager.instance().endRequest( externalContext.getSessionMap() ); FacesLifecycle.endRequest( facesContext.getExternalContext() ); }