@Override public ExternalContext getObject() { return FacesContext.getCurrentInstance().getExternalContext(); } @Override
private void updateIterationStatus(FacesContext ctx, IterationStatus status) { if (varStatus != null) { Map<String, Object> attrs = ctx.getExternalContext().getRequestMap(); attrs.put(varStatus, status); } }
private void captureOrigValue(FacesContext ctx) { if (var != null || varStatus != null) { Map<String, Object> attrs = ctx.getExternalContext().getRequestMap(); if (var != null) { origValueOfVar = attrs.get(var); } if (varStatus != null) { origValueOfVarStatus = attrs.get(varStatus); } } }
public static boolean isRequestSource(UIComponent component, FacesContext context) { return component.getClientId(context).equals(context.getExternalContext().getRequestParameterMap().get(Constants.RequestParams.PARTIAL_SOURCE_PARAM)); }
public boolean isNodeSelectRequest(FacesContext context) { if (!ComponentUtils.isRequestSource(this, context)) { return false; } Map<String, String> params = context.getExternalContext().getRequestParameterMap(); String eventName = params.get(Constants.RequestParams.PARTIAL_BEHAVIOR_EVENT_PARAM); return eventName.equals("select"); } }
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; }
public static void setCurrentInstance(final PrimeApplicationContext context, final FacesContext facesContext) { facesContext.getExternalContext().getApplicationMap().put(INSTANCE_KEY, context); if (facesContext.getExternalContext().getContext() instanceof ServletContext) { ((ServletContext) facesContext.getExternalContext().getContext()).setAttribute(INSTANCE_KEY, context); } }
/** * Find the root {@link WebApplicationContext} for this web app, typically * loaded via {@link org.springframework.web.context.ContextLoaderListener}. * <p>Will rethrow an exception that happened on root context startup, * to differentiate between a failed context startup and no context at all. * @param fc the FacesContext to find the web application context for * @return the root WebApplicationContext for this web app, or {@code null} if none * @see org.springframework.web.context.WebApplicationContext#ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE */ @Nullable public static WebApplicationContext getWebApplicationContext(FacesContext fc) { Assert.notNull(fc, "FacesContext must not be null"); Object attr = fc.getExternalContext().getApplicationMap().get( WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); if (attr == null) { return null; } if (attr instanceof RuntimeException) { throw (RuntimeException) attr; } if (attr instanceof Error) { throw (Error) attr; } if (!(attr instanceof WebApplicationContext)) { throw new IllegalStateException("Root context attribute is not of type WebApplicationContext: " + attr); } return (WebApplicationContext) attr; }
@Override public Object getValue(ELContext elContext, Object base, Object property) { if (EL_NAME.equals(property)) { elContext.setPropertyResolved(true); FacesContext context = FacesContext.getCurrentInstance(); ExceptionInfo info = (ExceptionInfo) context.getAttributes().get(ExceptionInfo.ATTRIBUTE_NAME); if (info == null) { info = (ExceptionInfo) context.getExternalContext().getSessionMap().get(ExceptionInfo.ATTRIBUTE_NAME); } return info; } return null; }
@Override public boolean isAjaxRequest() { return getWrapped().isAjaxRequest() || FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().containsKey("javax.faces.partial.ajax"); }
@Override public void queueEvent(FacesEvent event) { FacesContext context = getFacesContext(); if (ComponentUtils.isRequestSource(this, context) && (event instanceof AjaxBehaviorEvent)) { String eventName = context.getExternalContext().getRequestParameterMap().get(Constants.RequestParams.PARTIAL_BEHAVIOR_EVENT_PARAM); customEvents.put(eventName, (AjaxBehaviorEvent) event); } else { super.queueEvent(event); } }
private boolean isToggleRequest(FacesContext context) { Map<String, String> params = context.getExternalContext().getRequestParameterMap(); String clientId = getClientId(context); return params.get(clientId + "_expandNode") != null || params.get(clientId + "_collapseNode") != null; }
private void restoreOrigValue(FacesContext ctx) { if (var != null || varStatus != null) { Map<String, Object> attrs = ctx.getExternalContext().getRequestMap(); if (var != null) { if (origValueOfVar != null) { attrs.put(var, origValueOfVar); } else { attrs.remove(var); } } if (varStatus != null) { if (origValueOfVarStatus != null) { attrs.put(varStatus, origValueOfVarStatus); } else { attrs.remove(varStatus); } } } }
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; }
/** * Calculates the current viewId - we can't get it from the ViewRoot if it's not available. * * @param context The {@link FacesContext}. * @return The current viewId. */ public static String calculateViewId(FacesContext context) { Map<String, Object> requestMap = context.getExternalContext().getRequestMap(); String viewId = (String) requestMap.get("javax.servlet.include.path_info"); if (viewId == null) { viewId = context.getExternalContext().getRequestPathInfo(); } if (viewId == null) { viewId = (String) requestMap.get("javax.servlet.include.servlet_path"); } if (viewId == null) { viewId = context.getExternalContext().getRequestServletPath(); } return viewId; }
/** * 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; }
@Override public ExternalContext getObject() { return FacesContext.getCurrentInstance().getExternalContext(); } @Override
@Override public boolean isPartialRequest() { return getWrapped().isPartialRequest() || FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().containsKey("javax.faces.partial.execute"); }
/** * 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) + "'});"); }
public boolean isResizeRequest(FacesContext context) { Map<String, String> params = context.getExternalContext().getRequestParameterMap(); String clientId = getClientId(context); return params.get(clientId + "_colResize") != null; }