Package javax.faces.context

Examples of javax.faces.context.ExternalContext


        return _defaultSuffix;
    }

    protected String getRenderedViewId(FacesContext context, String actionId)
    {
        ExternalContext eContext = context.getExternalContext();
        String viewId = actionId;
        if (eContext.getRequestPathInfo() == null)
        {
            String viewSuffix = getDefaultSuffix(context);

            StringBuilder builder = new StringBuilder(viewId);
View Full Code Here


        Compiler compiler = createCompiler(context);

        _faceletFactory = createFaceletFactory(context, compiler);

        ExternalContext eContext = context.getExternalContext();
        _initializeBuffer(eContext);
        _initializeMode(eContext);

        log.finest("Initialization Successful");
    }
View Full Code Here

     * @param compiler
     *            the page compiler
     */
    protected void loadLibraries(FacesContext context, Compiler compiler)
    {
        ExternalContext eContext = context.getExternalContext();
       
        compiler.addTagLibrary(new CoreLibrary());
        compiler.addTagLibrary(new HtmlLibrary());
        compiler.addTagLibrary(new UILibrary());
        compiler.addTagLibrary(new JstlCoreLibrary());
        compiler.addTagLibrary(new JstlFnLibrary());
        compiler.addTagLibrary(new CompositeLibrary());
        compiler.addTagLibrary(new CompositeResourceLibrary());

        String param = _getStringParameter(eContext, PARAM_LIBRARIES, PARAM_LIBRARIES_DEPRECATED);
        if (param != null)
        {
            for (String library : param.split(";"))
            {
                try
                {
                    URL src = eContext.getResource(library.trim());
                    if (src == null)
                    {
                        throw new FileNotFoundException(library);
                    }

View Full Code Here

     * @param compiler
     *            the page compiler
     */
    protected void loadOptions(FacesContext context, Compiler compiler)
    {
        ExternalContext eContext = context.getExternalContext();

        // skip comments?
        compiler.setTrimmingComments(_getBooleanParameter(eContext, PARAM_SKIP_COMMENTS, PARAM_SKIP_COMMENTS_DEPRECATED, false));
    }
View Full Code Here

        if (lifecycle == null)
        {
            throw new NullPointerException("lifecycle");
        }
       
        ExternalContext externalContext = _externalContextFactory.getExternalContext(context, request, response);

        ExternalContext defaultExternalContext = null;
       
        if (_firstExternalContextInstance != null)
        {
            defaultExternalContext = (ExternalContext)
                externalContext.getRequestMap().remove(
View Full Code Here

    protected void afterFormElementsEnd(FacesContext facesContext,
            UIComponent component) throws IOException {
        super.afterFormElementsEnd(facesContext, component);
       
        ResponseWriter writer = facesContext.getResponseWriter();
        ExternalContext extContext = facesContext.getExternalContext();
        UIViewRoot root = facesContext.getViewRoot();
       
        for (UIComponent child : root.getComponentResources(facesContext,
             FORM_TARGET)) {
            child.encodeAll (facesContext);
View Full Code Here

     * {@inheritDoc}
     */
    @Override
    public void buildView(FacesContext context, UIViewRoot view) throws IOException
    {
        ExternalContext externalContext = context.getExternalContext();

        if (context.getPartialViewContext().isPartialRequest())
        {
            // try to get (or create) a ResponseSwitch and turn off the output
            Object origResponse = context.getExternalContext().getResponse();
            ResponseSwitch responseSwitch = ExternalContextUtils.getResponseSwitch(origResponse);
            if (responseSwitch == null)
            {
                // no ResponseSwitch installed yet - create one
                responseSwitch = ExternalContextUtils.createResponseSwitch(origResponse);
                if (responseSwitch != null)
                {
                    // install the ResponseSwitch
                    context.getExternalContext().setResponse(responseSwitch);
                }
            }
            if (responseSwitch != null)
            {
                responseSwitch.setEnabled(context, false);
            }
        }
       
        ServletResponse response = (ServletResponse) externalContext.getResponse();
        ServletRequest request = (ServletRequest) externalContext.getRequest();
       
        Locale locale = view.getLocale();
        response.setLocale(locale);
        Config.set(request, Config.FMT_LOCALE, context.getViewRoot().getLocale());

        String viewId = view.getViewId();
        ServletViewResponseWrapper wrappedResponse = new ServletViewResponseWrapper((HttpServletResponse) response);

        externalContext.setResponse(wrappedResponse);
        try
        {
            externalContext.dispatch(viewId);
        }
        catch (FacesException e)
        {
            // try to extract the most likely exceptions here
            // and provide a better error message for them
           
            String message = e.getMessage();
           
            // errors related to using facelets-only tags on a JSP page
            if (message != null)
            {
                // does the message contain "f" (prefix f of tags)
                // or the related uri http://java.sun.com/jsf/core
                if (message.contains("\"f\"")
                        || message.contains("\"" + CoreLibrary.Namespace + "\""))
                {
                    // check facelets-only f tags
                    for (String tag : FACELETS_ONLY_F_TAGS)
                    {
                        if (message.contains("\"" + tag + "\""))
                        {
                            String exceptionMessage = "The tag f:" + tag +
                                    " is only available on facelets.";
                            throw new FacesException(exceptionMessage,
                                    new FaceletsOnlyException(exceptionMessage, e.getCause()));
                        }
                    }
                } 
                else if (message.contains("\"h\"")
                        || message.contains("\"" + HtmlLibrary.Namespace + "\""))
                {
                    // check facelets-only h tags
                    for (String tag : FACELETS_ONLY_H_TAGS)
                    {
                        if (message.contains("\"" + tag + "\""))
                        {
                            String exceptionMessage = "The tag h:" + tag +
                                    " is only available on facelets.";
                            throw new FacesException(exceptionMessage,
                                    new FaceletsOnlyException(exceptionMessage, e.getCause()));
                        }
                    }
                }
                else
                {
                    // check facelets-only namespaces
                    String namespace = null;
                    if (message.contains(UILibrary.Namespace))
                    {
                        namespace = UILibrary.Namespace;
                    }
                    else if (message.contains(CompositeLibrary.NAMESPACE))
                    {
                        namespace = CompositeLibrary.NAMESPACE;
                    }
                   
                    if (namespace != null)
                    {
                        // the message contains a facelets-only namespace
                        String exceptionMessage = "All tags with namespace " +
                                namespace + " are only available on facelets.";
                        throw new FacesException(exceptionMessage,
                                new FaceletsOnlyException(exceptionMessage, e.getCause()));
                    }
                }
            }
           
            // no rule applied to this Exception - rethrow it
            throw e;
        }
        finally
        {
            externalContext.setResponse(response);
        }

        boolean errorResponse = wrappedResponse.getStatus() < 200 || wrappedResponse.getStatus() > 299;
        if (errorResponse)
        {
View Full Code Here

     */
    @SuppressWarnings("unchecked")
    private Map<String, Object> _getMapFromSession(FacesContext context,
            String token, boolean createIfNeeded)
    {
        ExternalContext external = context.getExternalContext();
        Object session = external.getSession(true);

        Map<String, Object> map = null;

        // Synchronize on the session object to ensure that
        // we don't ever create two different caches
        synchronized (session)
        {
            map = (Map<String, Object>) external.getSessionMap().get(token);
            if ((map == null) && createIfNeeded)
            {
                map = new SubKeyMap<Object>(context.getExternalContext()
                        .getSessionMap(), token);
            }
View Full Code Here

     */
    @Override
    public boolean isRedirect()
    {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ExternalContext externalContext = facesContext.getExternalContext();
        Map<String, Object> requestMap = externalContext.getRequestMap();
        Boolean redirect = (Boolean) requestMap.get(FLASH_REDIRECT);
        if (redirect == null)
        {
            HttpServletResponse httpResponse = ExternalContextUtils.getHttpServletResponse(externalContext);
            if (httpResponse != null)
            {
                // Request values are lost after a redirect. We can create a
                // temporal cookie to pass the params between redirect calls.
                // It is better than use HttpSession object, because this cookie
                // is never sent by the server.
                Cookie cookie = (Cookie) externalContext.getRequestCookieMap()
                        .get(FLASH_REDIRECT);
                if (cookie != null)
                {
                    redirect = Boolean.TRUE;
                    // A redirect happened, so it is safe to remove the cookie, setting
                    // the maxAge to 0 seconds. The effect is we passed FLASH_REDIRECT param
                    // to this request object
                    cookie.setMaxAge(0);
                    cookie.setValue(null);
                    httpResponse.addCookie(cookie);
                    requestMap.put(FLASH_REDIRECT, redirect);
                }
                else
                {
                    redirect = Boolean.FALSE;
                }
            }
            else
            {
                // Note that on portlet world we can't create cookies,
                // so we are forced to use the session map. Anyway,
                // according to the Bridge implementation(for example see
                // org.apache.myfaces.portlet.faces.bridge.BridgeImpl)
                // session object is created at start faces request
                Map<String, Object> sessionMap = externalContext
                        .getSessionMap();
                redirect = (Boolean) sessionMap.get(FLASH_REDIRECT);
                if (redirect != null)
                {
                    sessionMap.remove(FLASH_REDIRECT);
View Full Code Here

    @Override
    public void setRedirect(boolean redirect)
    {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ExternalContext externalContext = facesContext.getExternalContext();
        Map<String, Object> requestMap = externalContext.getRequestMap();
       
        Boolean previousRedirect = (Boolean) requestMap.get(FLASH_REDIRECT);
        previousRedirect = (previousRedirect == null) ? Boolean.FALSE : previousRedirect;
       
        if (!previousRedirect.booleanValue() && redirect)
        {
            // This request contains a redirect. This condition is in general
            // triggered by a NavigationHandler. After a redirect all request scope
            // values get lost, so in order to preserve this value we need to
            // pass it between request. One strategy is use a cookie that is never sent
            // to the client. Other alternative is use the session map.
            Object response = externalContext.getResponse();
            if (response instanceof HttpServletResponse)
            {
                HttpServletResponse servletResponse = (HttpServletResponse) response;
                Cookie cookie = new Cookie(FLASH_REDIRECT,"true");
                cookie.setMaxAge(-1);
                servletResponse.addCookie(cookie);
            }
            else
            {
                externalContext.getSessionMap().put(FLASH_REDIRECT, redirect);
            }
        }
        requestMap.put(FLASH_REDIRECT, redirect);
    }
View Full Code Here

TOP

Related Classes of javax.faces.context.ExternalContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.