Search in sources :

Example 1 with FacesException

use of javax.faces.FacesException in project oxCore by GluuFederation.

the class ExternalResourceHandler method resolveUrl.

@Override
public URL resolveUrl(String path) {
    if (!useExternalResourceBase) {
        return this.parent.resolveUrl(path);
    }
    // First try external resource folder
    final File externalResource = new File(this.externalResourceBaseFolder, path);
    if (externalResource.exists()) {
        try {
            //                tryToUpdateCachedPageXML(path);
            log.debug("Found overriden resource: " + path);
            URL resource = externalResource.toURI().toURL();
            return resource;
        } catch (MalformedURLException ex) {
            throw new FacesException(ex);
        }
    }
    // Return default resource
    return this.parent.resolveUrl(path);
}
Also used : MalformedURLException(java.net.MalformedURLException) File(java.io.File) URL(java.net.URL) FacesException(javax.faces.FacesException)

Example 2 with FacesException

use of javax.faces.FacesException in project oxCore by GluuFederation.

the class UIInputContainer method getDefaultValidator.

/**
     * Get the default Bean Validation Validator to read the contraints for a property.
     */
private Validator getDefaultValidator(final FacesContext context) throws FacesException {
    if (!beanValidationPresent) {
        return null;
    }
    ValidatorFactory validatorFactory;
    Object cachedObject = context.getExternalContext().getApplicationMap().get(BeanValidator.VALIDATOR_FACTORY_KEY);
    if (cachedObject instanceof ValidatorFactory) {
        validatorFactory = (ValidatorFactory) cachedObject;
    } else {
        try {
            validatorFactory = Validation.buildDefaultValidatorFactory();
        } catch (ValidationException e) {
            throw new FacesException("Could not build a default Bean Validator factory", e);
        }
        context.getExternalContext().getApplicationMap().put(BeanValidator.VALIDATOR_FACTORY_KEY, validatorFactory);
    }
    return validatorFactory.getValidator();
}
Also used : ValidationException(javax.validation.ValidationException) ValidatorFactory(javax.validation.ValidatorFactory) FacesException(javax.faces.FacesException)

Example 3 with FacesException

use of javax.faces.FacesException in project deltaspike by apache.

the class ClientWindowHelper method handleInitialRedirect.

/**
     * Handles the initial redirect for the LAZY mode, if no windowId is available in the current request URL.
     *
     * @param facesContext the {@link FacesContext}
     * @param newWindowId the new windowId
     */
public static void handleInitialRedirect(FacesContext facesContext, String newWindowId) {
    // store the new windowId as context attribute to prevent infinite loops
    // #sendRedirect will append the windowId (from ClientWindow#getWindowId again) to the redirectUrl
    facesContext.getAttributes().put(INITIAL_REDIRECT_WINDOW_ID, newWindowId);
    ExternalContext externalContext = facesContext.getExternalContext();
    String url = constructRequestUrl(externalContext);
    // remember the initial redirect windowId till the next request - see #729
    addRequestWindowIdCookie(facesContext, newWindowId, newWindowId);
    try {
        externalContext.redirect(url);
    } catch (IOException e) {
        throw new FacesException("Could not send initial redirect!", e);
    }
}
Also used : ExternalContext(javax.faces.context.ExternalContext) IOException(java.io.IOException) FacesException(javax.faces.FacesException)

Example 4 with FacesException

use of javax.faces.FacesException in project deltaspike by apache.

the class ClientSideWindowStrategy method sendWindowHandlerHtml.

protected void sendWindowHandlerHtml(ExternalContext externalContext, String windowId) {
    HttpServletResponse httpResponse = (HttpServletResponse) externalContext.getResponse();
    try {
        httpResponse.setStatus(HttpServletResponse.SC_OK);
        httpResponse.setContentType("text/html");
        String windowHandlerHtml = clientWindowConfig.getClientWindowHtml();
        if (windowId == null) {
            windowId = UNINITIALIZED_WINDOW_ID_VALUE;
        }
        // set the windowId value in the javascript code
        windowHandlerHtml = windowHandlerHtml.replace(WINDOW_ID_REPLACE_PATTERN, windowId);
        // set the current request url
        // on the client we can't use window.location as the location
        // could be a different when using forwards
        windowHandlerHtml = windowHandlerHtml.replace(REQUEST_URL_REPLACE_PATTERN, ClientWindowHelper.constructRequestUrl(externalContext));
        // set the noscript-URL for users with no JavaScript
        windowHandlerHtml = windowHandlerHtml.replace(NOSCRIPT_URL_REPLACE_PATTERN, getNoscriptUrl(externalContext));
        OutputStream os = httpResponse.getOutputStream();
        try {
            os.write(windowHandlerHtml.getBytes());
        } finally {
            os.close();
        }
    } catch (IOException ioe) {
        throw new FacesException(ioe);
    }
}
Also used : OutputStream(java.io.OutputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) FacesException(javax.faces.FacesException)

Example 5 with FacesException

use of javax.faces.FacesException in project tomee by apache.

the class TomEEFacesConfigurationProviderFactory method getFacesConfigurationProvider.

@Override
public FacesConfigurationProvider getFacesConfigurationProvider(final ExternalContext externalContext) {
    FacesConfigurationProvider returnValue = (FacesConfigurationProvider) externalContext.getApplicationMap().get(FACES_CONFIGURATION_PROVIDER_INSTANCE_KEY);
    if (returnValue == null) {
        final ExternalContext extContext = externalContext;
        try {
            returnValue = resolveFacesConfigurationProviderFromService(extContext);
            externalContext.getApplicationMap().put(FACES_CONFIGURATION_PROVIDER_INSTANCE_KEY, returnValue);
        } catch (final ClassNotFoundException | NoClassDefFoundError e) {
        // ignore
        } catch (final InstantiationException | InvocationTargetException | IllegalAccessException e) {
            getLogger().log(Level.SEVERE, "", e);
        } catch (final PrivilegedActionException e) {
            throw new FacesException(e);
        }
    }
    return returnValue;
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) ExternalContext(javax.faces.context.ExternalContext) FacesConfigurationProvider(org.apache.myfaces.spi.FacesConfigurationProvider) InvocationTargetException(java.lang.reflect.InvocationTargetException) FacesException(javax.faces.FacesException)

Aggregations

FacesException (javax.faces.FacesException)5 IOException (java.io.IOException)2 ExternalContext (javax.faces.context.ExternalContext)2 File (java.io.File)1 OutputStream (java.io.OutputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 PrivilegedActionException (java.security.PrivilegedActionException)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 ValidationException (javax.validation.ValidationException)1 ValidatorFactory (javax.validation.ValidatorFactory)1 FacesConfigurationProvider (org.apache.myfaces.spi.FacesConfigurationProvider)1