Java Code Examples for javax.faces.context.FacesContext.getExternalContext()
The following are Jave code examples for showing how to use
getExternalContext() of the
javax.faces.context.FacesContext
class.
You can vote up the examples you like. Your votes will be used in our system to get
more good examples.
+ Save this method
Example 1
Project: myfaces-trinidad File: SimpleInputFileRenderer.java View Source Code | 7 votes |
@Override protected void encodeAllAsElement( FacesContext context, RenderingContext rc, UIComponent component, FacesBean bean ) throws IOException { // call super... super.encodeAllAsElement(context, rc, component, bean); // now evaluate the EL // We need to evaluate it here and store it on the sessionMap because // during UploadedFileProcessor.processFile() there is no FacesContext RequestContext requestContext = RequestContext.getCurrentInstance(); Object maxMemory = requestContext.getUploadedFileMaxMemory(); Object maxDiskSpace = requestContext.getUploadedFileMaxDiskSpace(); Object tempDir = requestContext.getUploadedFileTempDir(); ExternalContext external = context.getExternalContext(); Map<String, Object> sessionMap = external.getSessionMap(); sessionMap.put(UploadedFileProcessor.MAX_MEMORY_PARAM_NAME, maxMemory); sessionMap.put(UploadedFileProcessor.MAX_DISK_SPACE_PARAM_NAME, maxDiskSpace); sessionMap.put(UploadedFileProcessor.TEMP_DIR_PARAM_NAME, tempDir); }
Example 2
Project: myfaces-trinidad File: SkinFactoryImpl.java View Source Code | 6 votes |
/** * given the skinId, pass back the Skin. * * @param context FacesContext. If not available, pass in null. * @param skinId * @return Skin that is in this SkinFactory and has the skinId. * @deprecated use SkinProvider to query skins */ @Deprecated @Override public Skin getSkin(FacesContext context, String skinId) { context = SkinUtils.getNonNullFacesContext(context); if (skinId == null) { _LOG.warning("CANNOT_GET_SKIN_WITH_NULL_SKINID"); return null; } ExternalContext ec = context.getExternalContext(); SkinMetadata skinMetadata = new SkinMetadata.Builder().id(skinId).build(); return SkinProvider.getCurrentInstance(ec).getSkin(ec, skinMetadata); }
Example 3
Project: myfaces-trinidad File: XMLMenuModel.java View Source Code | 6 votes |
/** * Returns the map of content handlers * which hold the state of one XML tree. * @param scopeMap * @return */ protected Map<Object, List<MenuContentHandler> > getContentHandlerMap() { FacesContext facesContext = FacesContext.getCurrentInstance(); ExternalContext externalContext = facesContext.getExternalContext(); Map<String, Object> scopeMap = externalContext.getApplicationMap(); Object lock = externalContext.getContext(); // cannot use double checked lock here as // we cannot mark the reference as volatile // therefore any reads should happen inside // a synchronized block. synchronized (lock) { TransientHolder<Map<Object, List<MenuContentHandler> >> holder = (TransientHolder<Map<Object, List<MenuContentHandler> >>) scopeMap.get(_CACHED_MODELS_KEY); Map<Object, List<MenuContentHandler>> contentHandlerMap = (holder != null) ? holder.getValue() : null; if (contentHandlerMap == null) { contentHandlerMap = new ConcurrentHashMap<Object, List<MenuContentHandler>>(); scopeMap.put(_CACHED_MODELS_KEY, TransientHolder.newTransientHolder( contentHandlerMap) ); scopeMap.put(_CACHED_MODELS_ID_CNTR_KEY,new AtomicInteger(-1)); } return contentHandlerMap; } }
Example 4
Project: ctsms File: ValidatorUtil.java View Source Code | 6 votes |
public static boolean skipValidation(final FacesContext context) { final ExternalContext externalContext = context.getExternalContext(); final Object validate = externalContext.getRequestMap().get(GetParamNames.VALIDATE.toString()); if (validate != null) { return !(Boolean) validate; } Iterator<Entry<String, String[]>> parameterValuesIt = externalContext.getRequestParameterValuesMap() .entrySet().iterator(); while (parameterValuesIt.hasNext()) { Entry<String, String[]> parameterValues = parameterValuesIt.next(); final String key = parameterValues.getKey(); Iterator<String> idPrefixIt = VALIDATION_REQUIRED_COMPONENT_ID_PREFIXES.iterator(); while (idPrefixIt.hasNext()) { String idPrefix = idPrefixIt.next(); if (key.contains(idPrefix)) { externalContext.getRequestMap().put(GetParamNames.VALIDATE.toString(), Boolean.TRUE); return false; } } } externalContext.getRequestMap().put(GetParamNames.VALIDATE.toString(), Boolean.FALSE); return true; }
Example 5
Project: myfaces-trinidad File: UIXEditableValueTemplate.java View Source Code | 6 votes |
/** * Checks if the <code>validate()</code> should interpret an empty * submitted value should be handle as <code>NULL</code> * * @return a (cached) boolean to identify the interpretation as null */ public static boolean shouldInterpretEmptyStringSubmittedValuesAsNull(FacesContext context) { ExternalContext ec = context.getExternalContext(); Boolean interpretEmptyStringAsNull = (Boolean)ec.getApplicationMap().get(TRINIDAD_EMPTY_VALUES_AS_NULL_PARAM_NAME); // not yet cached... if (interpretEmptyStringAsNull == null) { // parses the web.xml to get the "javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL" value String param = ec.getInitParameter(JSF_SPEC_EMPTY_VALUES_AS_NULL_PARAM_NAME); // evaluate the context parameter interpretEmptyStringAsNull = "true".equalsIgnoreCase(param); // cache the parsed value ec.getApplicationMap().put(TRINIDAD_EMPTY_VALUES_AS_NULL_PARAM_NAME, interpretEmptyStringAsNull); } return interpretEmptyStringAsNull; }
Example 6
Project: myfaces-trinidad File: PartialViewContextImpl.java View Source Code | 6 votes |
public PartialViewContextImpl(FacesContext context) { _context = context; ExternalContext extContext = context.getExternalContext(); _requestType = ReqType.FULL; if (_PARTIAL_AJAX.equals(extContext.getRequestHeaderMap().get(_FACES_REQUEST))) { // This request was sent with jsf.ajax.request() if (extContext.getRequestParameterMap().get(_TRINIDAD_PPR) != null) _requestType = ReqType.AJAX_LEGACY; else _requestType = ReqType.AJAX; } else if (CoreRenderKit.isLegacyPartialRequest(extContext)) { _requestType = ReqType.LEGACY; } }
Example 7
Project: oscm File: EnterpriseLandingpageCtrl.java View Source Code | 5 votes |
public void entrySelected() { FacesContext context = FacesContext.getCurrentInstance(); ExternalContext extContext = context.getExternalContext(); LandingpageEntryModel selectedEntry = findSelectedEntry(model .getSelectedEntryKey()); try { JSFUtils.redirect(extContext, selectedEntry.getRedirectUrl()); } catch (Exception e) { extContext.log(getClass().getName() + ".startService()", e); } finally { // reset requested key; model.setSelectedEntryKey(null); model.setSelectedCategory(0); } }
Example 8
Project: myfaces-trinidad File: UIXComponentBase.java View Source Code | 5 votes |
private static boolean _warnedClientIdCachingConfig(FacesContext context) { ExternalContext external = context.getExternalContext(); Map<String, Object> appMap = external.getApplicationMap(); return Boolean.TRUE.equals(appMap.get(_WARNED_CLIENT_ID_CACHING_KEY)); }
Example 9
Project: myfaces-trinidad File: UIXComponentBase.java View Source Code | 5 votes |
private static void _clientIdCachingConfigWarned(FacesContext context) { ExternalContext external = context.getExternalContext(); Map<String, Object> appMap = external.getApplicationMap(); appMap.put(_WARNED_CLIENT_ID_CACHING_KEY, Boolean.TRUE); }
Example 10
Project: myfaces-trinidad File: CoreRenderKit.java View Source Code | 5 votes |
@SuppressWarnings("unchecked") public boolean shortCircuitRenderView( FacesContext context) throws IOException { ExternalContext ec = context.getExternalContext(); if (isPartialRequest(ec)) { Map<String, Object> requestMap = ec.getRequestMap(); UIViewRoot originalRoot = (UIViewRoot) requestMap.get( TrinidadPhaseListener.INITIAL_VIEW_ROOT_KEY); // If we're doing a partial update, and the page has changed, switch to a // full page context. if (context.getViewRoot() != originalRoot) { ViewHandler vh = context.getApplication().getViewHandler(); String viewId = context.getViewRoot().getViewId(); String redirect = vh.getActionURL(context, viewId); String encodedRedirect = ec.encodeActionURL(redirect); ec.redirect(encodedRedirect); if (_LOG.isFine()) { _LOG.fine("Page navigation to {0} happened during a PPR request " + "on {1}; Apache Trinidad is forcing a redirect.", new String[]{viewId, originalRoot.getViewId()}); } return true; } } // =-=AEW We could look for PPR requests that have no // requested partial targets, in particular requests // that simply need to launch a dialog. return false; }
Example 11
Project: myfaces-trinidad File: FacesURLEncoder.java View Source Code | 5 votes |
/** * @todo Does this ever need to be absolute? */ public FacesURLEncoder(FacesContext context) { _externalContext = context.getExternalContext(); String viewId = context.getViewRoot().getViewId(); _defaultURL = context.getApplication().getViewHandler().getActionURL(context, viewId); }
Example 12
Project: myfaces-trinidad File: TranslationsResourceLoader.java View Source Code | 5 votes |
protected Skin getSkin(FacesContext context) { Skin skin = null; ExternalContext externalContext = context.getExternalContext(); SkinProvider skinProvider = SkinProvider.getCurrentInstance(externalContext); Object skinIdObj = externalContext.getRequestParameterMap().get("skinId"); if (skinIdObj != null) skin = skinProvider.getSkin(externalContext, new SkinMetadata.Builder().id(skinIdObj.toString()).build()); return skin; }
Example 13
Project: myfaces-trinidad File: ViewDeclarationLanguageFactoryImpl.java View Source Code | 5 votes |
private InternalView _getInternalView( FacesContext context, String viewId) { Object cached = _internalViewCache.get(viewId); if (cached != null) { return ((cached == _NOT_FOUND) ? null : (InternalView)cached); } InternalView internal = _internalViews.get(viewId); if (internal == null) { // If we're using suffix-mapping, then any internal viewId will // get affixed with ".jsp" or ".jspx"; try trimming that off // if present ExternalContext external = context.getExternalContext(); // Only bother when using suffix-mapping (path info will always // be non-null for prefix-mapping) if (external.getRequestPathInfo() == null) { String suffix = external.getInitParameter("javax.faces.DEFAULT_SUFFIX"); if (suffix == null) suffix = ".jspx"; if (viewId.endsWith(suffix)) { String viewIdWithoutSuffix = viewId.substring( 0, viewId.length() - suffix.length()); internal = _internalViews.get(viewIdWithoutSuffix); } } } _internalViewCache.put(viewId, (internal == null) ? _NOT_FOUND : internal); return internal; }
Example 14
Project: ProjetoFinalInitium File: ProvaBean.java View Source Code | 5 votes |
public void listarProvaAvaliador() { zerarLista(); FacesContext fc = FacesContext.getCurrentInstance(); ExternalContext ec = fc.getExternalContext(); HttpSession session = (HttpSession) ec.getSession(false); Usuario usuariologado=(Usuario)session.getAttribute("usuario"); if (parecerProvaFiltrada != null && !parecerProvaFiltrada.isEmpty()) { list.addAll(dao.findByNameAvaliador(parecerProvaFiltrada,usuariologado)); } else { list.addAll(dao.findAllAvaliador(usuariologado)); } }
Example 15
Project: myfaces-trinidad File: UIXEditableValueTemplate.java View Source Code | 4 votes |
/** * This boolean indicates if Bean Validation is present. * * @return a (cached) boolean to identify if bean validation is present */ private static boolean _isBeanValidationAvailable(FacesContext context) { ExternalContext ec = context.getExternalContext(); Boolean couldLoadBeanValidationAPI = (Boolean) ec.getApplicationMap().get(TRINIDAD_BEAN_VALIDATION_AVAILABLE); // not yet cached... if (couldLoadBeanValidationAPI == null) { try { couldLoadBeanValidationAPI = Boolean.valueOf(ClassLoaderUtils.loadClass("javax.validation.Validation") != null); if (couldLoadBeanValidationAPI) { try { // Trial-error approach to check for Bean Validation impl existence. Validation.buildDefaultValidatorFactory().getValidator(); } catch (Exception validationException) { // From section 3.5.6.2 of the spec // "If the BeanValidator is used an no ValidatorFactory can be retrieved, a FacesException is raised. " // Only BeanValidator needs to throw a FacesException, in this case just log the message // and behave as if bean validation is disabled _LOG.warning("VALIDATOR_FACTORY_UNAVAILABLE", validationException.getMessage()); couldLoadBeanValidationAPI = Boolean.FALSE; } } } catch (ClassNotFoundException cnfe) { // SPEC section 3.5.6.2: // if a Bean Validation provider is not present, bean validation is disabled // TODO need a better warning (i18n) here, which has more information _LOG.warning("A Bean Validation provider is not present, therefore bean validation is disabled"); couldLoadBeanValidationAPI = Boolean.FALSE; } // cache the parsed value ec.getApplicationMap().put(TRINIDAD_BEAN_VALIDATION_AVAILABLE, couldLoadBeanValidationAPI); } return couldLoadBeanValidationAPI; }
Example 16
Project: myfaces-trinidad File: StateManagerImpl.java View Source Code | 4 votes |
private Object _saveStateToCache(FacesContext context, Object viewState, UIViewRoot root) { ExternalContext extContext = context.getExternalContext(); RequestContext trinContext = RequestContext.getCurrentInstance(); TokenCache cache = _getViewCache(trinContext, extContext); assert(cache != null); // get per window view cache key with "." separator suffix to separate the SubKeyMap keys String subkey = _getViewCacheKey(extContext, trinContext, _SUBKEY_SEPARATOR); Map<String, Object> sessionMap = extContext.getSessionMap(); SubKeyMap<PageState> stateMap = new SubKeyMap<PageState>(sessionMap, subkey); // Sadly, we can't save just a SerializedView, because we should // save a serialized object, and SerializedView is a *non*-static // inner class of StateManager PageState pageState = new PageState( context, _getOrCreateViewRootStateRefFactory(context, trinContext), viewState, // Save the view root into the page state as a transient // if this feature has not been disabled root); String requestToken = _getRequestTokenForResponse(context); String token; // If we have a cached token that we want to reuse, // and that token hasn't disappeared from the cache already // (unlikely, but not impossible), use the stateMap directly // without asking the cache for a new token if ((requestToken != null) && cache.isAvailable(requestToken)) { // NOTE: under *really* high pressure, the cache might // have been emptied between the isAvailable() call and // this put(). This seems sufficiently implausible to // be worth punting on stateMap.put(requestToken, pageState); token = requestToken; // NOTE 2: we have not pinned this reused state to any old state // This is OK for current uses of pinning and state reuse, // as pinning stays constant within a window, and we're not // erasing pinning at all. } else { // See if we should pin this new state to any old state String pinnedToken = (String)extContext.getRequestMap().get(_PINNED_STATE_TOKEN_KEY); token = cache.addNewEntry(pageState, stateMap, pinnedToken); } assert(token != null); // And store the token for this request extContext.getRequestMap().put(_REQUEST_STATE_TOKEN_KEY, token); // clear out the view root cache, passing in the session key for the new active state String newActivePageStateKey = stateMap.getBaseKey(token); _clearViewRootCache(extContext, newActivePageStateKey); // Create a "tokenView" which abuses state to store // our token only return new Object[]{token, null}; }
Example 17
Project: myfaces-trinidad File: StateManagerImpl.java View Source Code | 4 votes |
/** * @return the holder for the factory to use for creating references to the UIViewRootState. If * <code>null</code>, no UIViewRoot caching should be performed. */ private static AtomicReference<PseudoReferenceFactory<ViewRootState>> _getViewRootStateRefFactoryHolder(FacesContext context, RequestContext trinContext) { ConcurrentMap<String, Object> sharedAppMap = trinContext.getApplicationScopedConcurrentMap(); AtomicReference<PseudoReferenceFactory<ViewRootState>> factoryHolder = (AtomicReference<PseudoReferenceFactory<ViewRootState>>)sharedAppMap.get(CACHE_VIEW_ROOT_INIT_PARAM); if (factoryHolder != null) { return factoryHolder; } else { ExternalContext extContext = context.getExternalContext(); String viewRootCaching = extContext.getInitParameter(CACHE_VIEW_ROOT_INIT_PARAM); String caseInsensitiveViewRootCaching; if ((viewRootCaching != null) && (viewRootCaching.length() > 0)) { caseInsensitiveViewRootCaching = viewRootCaching.toLowerCase(); } else { // ViewRootCaching conflicts with jsf >= 2,2 if (JsfUtils.IS_JSF_2_2) { caseInsensitiveViewRootCaching = "false"; } else { caseInsensitiveViewRootCaching = "true"; // the default } } PseudoReferenceFactory<ViewRootState> factory; if ("false".equals(caseInsensitiveViewRootCaching)) { factory = null; } else if ("strong".equals(caseInsensitiveViewRootCaching)) factory = new StrongPseudoReferenceFactory<ViewRootState>(); else if ("soft".equals(caseInsensitiveViewRootCaching)) factory = new SoftPseudoReferenceFactory<ViewRootState>(); else if ("true".equals(caseInsensitiveViewRootCaching)) { factory = _instantiateDefaultPseudoReferenceFactory(); } else { factory = _instantiatePseudoReferenceFactoryFromClass(viewRootCaching); if (factory == null) { // we had an error, so use the default factory = _instantiateDefaultPseudoReferenceFactory(); } } // use a placeholder for null, since ConcurrentHashMap can't store null; factoryHolder = new AtomicReference<PseudoReferenceFactory<ViewRootState>>(factory); sharedAppMap.put(CACHE_VIEW_ROOT_INIT_PARAM, factoryHolder); return factoryHolder; } }
Example 18
Project: myfaces-trinidad File: RequestContext.java View Source Code | 4 votes |
/** * <p> * Returns the WindowManager for this request. A non-null WindowManager * will always be returned. * </p><p> * The default implementation uses the first WindowManagerFactory specified * implementation class in a file named * <code>org.apache.myfaces.trinidad.context.WindowManagerFactory</code> * in the <code>META-INF/services</code> directory and uses the WindowManagerFactory * to create the WindowManager for this Session. If no WindowManagerFactory is * found, a default WindowManager that never returns any Windows is used. * </p> * @return the WindowManager used for this Session. */ public WindowManager getWindowManager() { // implement getWindowManager() in RequestContext for backwards compatibility // check if we have cached it for the request WindowManager windowManager = _windowManager; // get instance using the WindowManagerFactory if (windowManager == null) { FacesContext context = FacesContext.getCurrentInstance(); // just in case we're called before the real JSF lifecycle starts if (context != null) { // check if we have cached it per session ExternalContext extContext = context.getExternalContext(); // create a new instance using the WindowManagerFactory ConcurrentMap<String, Object> concurrentAppMap = getApplicationScopedConcurrentMap(); WindowManagerFactory windowManagerFactory = (WindowManagerFactory)concurrentAppMap.get( _WINDOW_MANAGER_FACTORY_CLASS_NAME); if (windowManagerFactory == null) { // we haven't registered a WindowManagerFactory yet, so use the services api to see // if a factory has been registered List<WindowManagerFactory> windowManagerFactories = ClassLoaderUtils.getServices(_WINDOW_MANAGER_FACTORY_CLASS_NAME); if (windowManagerFactories.isEmpty()) { // no factory registered so use the factory that returns dummy stub WindowManagers windowManagerFactory = _STUB_WINDOW_MANAGER_FACTORY; } else { // only one WindowManager is allowed, use it windowManagerFactory = windowManagerFactories.get(0); } // save the WindowManagerFactory to the application if it hasn't already been saved // if it has been saved, use the previously registered WindowManagerFactory WindowManagerFactory oldWindowManagerFactory = (WindowManagerFactory) concurrentAppMap.putIfAbsent(_WINDOW_MANAGER_FACTORY_CLASS_NAME, windowManagerFactory); if (oldWindowManagerFactory != null) windowManagerFactory = oldWindowManagerFactory; } // create WindowManagerFactory // get the WindowManager from the factory. The factory will create a new instance // for this session if necessary windowManager = windowManagerFactory.getWindowManager(extContext); // remember for the next call on this thread _windowManager = windowManager; } } return windowManager; }
Example 19
Project: myfaces-trinidad File: SkinPregenerationService.java View Source Code | 4 votes |
private static String _getSkinId(FacesContext context) { ExternalContext external = context.getExternalContext(); return external.getRequestParameterMap().get(_SKIN_ID_REQUEST_PARAM); }
Example 20
Project: lams File: FacesContextUtils.java View Source Code | 3 votes |
/** * 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 */ 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; }