Class Faces


  • public final class Faces
    extends Object

    Collection of utility methods for the Faces API that are mainly shortcuts for obtaining stuff from the thread local FacesContext. In effects, it 'flattens' the hierarchy of nested objects. Do note that using the hierarchy is actually a better software design practice, but can lead to verbose code.

    Next to those oneliner delegate calls, there are also some helpful methods which eliminates multiline boilerplate code, such as getLocale() which returns sane fallback values, a more convenient redirect(String, Object...) which automatically prepends the context path when the path does not start with / and offers support for URL encoding of request parameters supplied by varargs argument, and several useful sendFile(File, boolean) methods which allows you to provide a File, byte[] or InputStream as a download to the client.

    Usage

    Some examples:

     // Get a session attribute (no explicit cast necessary!).
     User user = Faces.getSessionAttribute("user");
     
     // Evaluate EL programmatically (no explicit cast necessary!).
     Item item = Faces.evaluateExpressionGet("#{item}");
     
     // Get a cookie value.
     String cookieValue = Faces.getRequestCookie("cookieName");
     
     // Get all supported locales with default locale as first item.
     List<Locale> supportedLocales = Faces.getSupportedLocales();
     
     // Check in e.g. preRenderView if session has been timed out.
     if (Faces.hasSessionTimedOut()) {
         Messages.addGlobalWarn("Oops, you have been logged out because your session was been timed out!");
     }
     
     // Get value of <f:metadata><f:attribute name="foo"> of different view without building it.
     String foo = Faces.getMetadataAttribute("/other.xhtml", "foo");
     
     // Send a redirect with parameters UTF-8 encoded in query string.
     Faces.redirect("product.xhtml?id=%d&name=%s", product.getId(), product.getName());
     
     // Invalidate the session and send a redirect.
     public void logout() {
         Faces.invalidateSession();
         Faces.redirect("login.xhtml"); // Can by the way also be done by return "login?faces-redirect=true" if in action method.
     }
     
     // Provide a file as attachment.
     public void download() {
         Faces.sendFile(new File("/path/to/file.ext"), true);
     }
     
     // Provide a file as attachment via output stream callback.
     public void download() {
         Faces.sendFile("file.txt", true, output -> {
             try (PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8))) {
                 writer.println("Hello world");
             }
         });
     }
     

    FacesLocal

    Note that there's normally a minor overhead in obtaining the thread local FacesContext. In case client code needs to call methods in this class multiple times it's expected that performance will be slightly better if instead the FacesContext is obtained once and the required methods are called on that, although the difference is practically negligible when used in modern server hardware.

    In such case, consider using FacesLocal instead. The difference with Faces is that no one method of FacesLocal obtains the FacesContext from the current thread by FacesContext.getCurrentInstance(). This job is up to the caller.

    #{faces} in EL

    Since OmniFaces 2.6, all methods of Faces utility class which start with "get" or "is", and take no parameters, and return either String or boolean, and are not related to response nor to session or flash (for which already implicit EL objects #{session} and #{flash} exist), will be available as properties of the implicit object #{faces}. Examples are:

     #{faces.development}
     #{faces.serverInfo}
     #{faces.ajaxRequest}
     #{faces.requestBaseURL}
     #{faces.requestURLWithQueryString}
     
    Author:
    Arjan Tijms, Bauke Scholtz
    See Also:
    FacesLocal, Servlets, FacesELResolver
    • Method Detail

      • getContext

        public static FacesContext getContext()
        Returns the current faces context.

        Note that whenever you absolutely need this method to perform a general task, you might want to consider to submit a feature request to OmniFaces in order to add a new utility method which performs exactly this general task.

        Returns:
        The current faces context.
        See Also:
        FacesContext.getCurrentInstance()
      • getContext

        public static FacesContext getContext​(ELContext elContext)
        Returns the faces context that's stored in an ELContext.

        Note that this only works for an ELContext that is created in the context of Faces.

        Parameters:
        elContext - the EL context to obtain the faces context from.
        Returns:
        the faces context that's stored in the given ELContext.
        Since:
        1.2
      • setContext

        public static void setContext​(FacesContext context)
        Sets the given faces context as current instance. Use this if you have a custom FacesContextWrapper which you'd like to (temporarily) use as the current instance of the faces context.
        Parameters:
        context - The faces context to be set as the current instance.
        Since:
        1.3
      • hasContext

        public static boolean hasContext()
        Returns true when the current faces context is available (i.e. it is not null).
        Returns:
        true when the current faces context is available.
        Since:
        2.0
      • getExternalContext

        public static ExternalContext getExternalContext()
        Returns the current external context.

        Note that whenever you absolutely need this method to perform a general task, you might want to consider to submit a feature request to OmniFaces in order to add a new utility method which performs exactly this general task.

        Returns:
        The current external context.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        FacesContext.getExternalContext()
      • getApplication

        public static Application getApplication()
        Returns the application singleton.

        Note that whenever you absolutely need this method to perform a general task, you might want to consider to submit a feature request to OmniFaces in order to add a new utility method which performs exactly this general task.

        Returns:
        The faces application singleton.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        FacesContext.getApplication()
      • getApplicationFromFactory

        public static Application getApplicationFromFactory()
        Gets the Faces Application singleton from the FactoryFinder.

        This method is an alternative for getApplication() for those situations where the FacesContext isn't available.

        Returns:
        The faces application singleton.
      • getPackage

        public static Package getPackage()
        Returns the package of the currently loaded Faces implementation.

        This is also available in EL as #{faces['package']}.

        Returns:
        The package of the currently loaded Faces implementation.
        Since:
        3.14
      • getImplInfo

        public static String getImplInfo()
        Returns the implementation information of currently loaded Faces implementation. E.g. "Mojarra 2.1.7-FCS".

        This is also available in EL as #{faces.implInfo}.

        Returns:
        The implementation information of currently loaded Faces implementation.
        See Also:
        Package.getImplementationTitle(), Package.getImplementationVersion()
      • getServerInfo

        public static String getServerInfo()
        Returns the server information of currently running application server implementation.

        This is also available in EL as #{faces.serverInfo}.

        Returns:
        The server information of currently running application server implementation.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        ServletContext.getServerInfo()
      • getProjectStage

        public static ProjectStage getProjectStage()
        Returns the project stage. This will return the jakarta.faces.PROJECT_STAGE context parameter in web.xml.
        Returns:
        The project stage.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        2.6
        See Also:
        Application.getProjectStage()
      • isDevelopment

        public static boolean isDevelopment()
        Returns whether we're in development stage. This will be the case when the jakarta.faces.PROJECT_STAGE context parameter in web.xml is set to Development.

        This is also available in EL as #{faces.development}.

        Returns:
        true if we're in development stage, otherwise false.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        Application.getProjectStage()
      • isSystemTest

        public static boolean isSystemTest()
        Returns whether we're in system test stage. This will be the case when the jakarta.faces.PROJECT_STAGE context parameter in web.xml is set to SystemTest.

        This is also available in EL as #{faces.systemTest}.

        Returns:
        true if we're in system test stage, otherwise false.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        2.6
        See Also:
        Application.getProjectStage()
      • isProduction

        public static boolean isProduction()
        Returns whether we're in production stage. This will be the case when the jakarta.faces.PROJECT_STAGE context parameter in web.xml is set to Production.

        This is also available in EL as #{faces.production}.

        Returns:
        true if we're in production stage, otherwise false.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        2.6
        See Also:
        Application.getProjectStage()
      • getMapping

        public static String getMapping()
        Determines and returns the faces servlet mapping used in the current request. If Faces is prefix mapped (e.g. /faces/*), then this returns the whole path, with a leading slash (e.g. /faces). If Faces is suffix mapped (e.g. *.xhtml), then this returns the whole extension (e.g. .xhtml).

        This is also available in EL as #{faces.mapping}.

        Returns:
        The faces servlet mapping (without the wildcard).
        Throws:
        NullPointerException - When faces context is unavailable.
        IllegalStateException - When mapping could not be determined.
        See Also:
        getRequestPathInfo(), getRequestServletPath()
      • isPrefixMapping

        public static boolean isPrefixMapping()
        Returns whether the faces servlet mapping used in the current request is a prefix mapping.

        This is also available in EL as #{faces.prefixMapping}.

        Returns:
        true if the faces servlet mapping used in the current request is a prefix mapping, otherwise false.
        See Also:
        getMapping(), isPrefixMapping(String)
      • isPrefixMapping

        public static boolean isPrefixMapping​(String mapping)
        Returns whether the given faces servlet mapping is a prefix mapping. Use this method in preference to isPrefixMapping() when you already have obtained the mapping from getMapping() so that the mapping won't be calculated twice.
        Parameters:
        mapping - The mapping to be tested.
        Returns:
        true if the faces servlet mapping used in the current request is a prefix mapping, otherwise false.
        Throws:
        NullPointerException - When mapping is null.
      • validationFailed

        public static void validationFailed()
        Signals Faces that the validations phase of the current request has failed. This can be invoked in any other phase than the validations phase. The value can be read by isValidationFailed() in Java and by #{facesContext.validationFailed} in EL.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        FacesContext.validationFailed()
      • isValidationFailed

        public static boolean isValidationFailed()
        Returns whether the validations phase of the current request has failed.

        This is also available in EL as #{faces.validationFailed}.

        Returns:
        true if the validations phase of the current request has failed, otherwise false.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        FacesContext.isValidationFailed()
      • resolveExpressionGet

        public static <T> T resolveExpressionGet​(Object base,
                                                 String property)
        Programmatically EL-resolve the given property on the given base object and return the resolved value.
        Type Parameters:
        T - The expected return type.
        Parameters:
        base - The base object whose property value is to be returned, or null to resolve a top-level variable.
        property - The property or variable to be resolved on the given base.
        Returns:
        The resolved value of the given property on the given base object.
        Throws:
        NullPointerException - When faces context is unavailable.
        ClassCastException - When T is of wrong type.
        Since:
        2.1
        See Also:
        Application.getELResolver(), ELResolver.getValue(ELContext, Object, Object)
      • resolveExpressionSet

        public static void resolveExpressionSet​(Object base,
                                                String property,
                                                Object value)
        Programmatically EL-resolve the given property on the given base object and set the given value.
        Parameters:
        base - The base object whose property value is to be set, or null to set a top-level variable.
        property - The property or variable to be set on the given base.
        value - The value to be set in the property on the given base.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        2.1
        See Also:
        Application.getELResolver(), ELResolver.setValue(ELContext, Object, Object, Object)
      • getContextAttribute

        public static <T> T getContextAttribute​(String name)
        Returns the Faces context attribute value associated with the given name.
        Type Parameters:
        T - The expected return type.
        Parameters:
        name - The Faces context attribute name.
        Returns:
        The Faces context attribute value associated with the given name.
        Throws:
        NullPointerException - When faces context is unavailable.
        ClassCastException - When T is of wrong type.
        Since:
        1.3
        See Also:
        FacesContext.getAttributes()
      • getContextAttribute

        public static <T> T getContextAttribute​(String name,
                                                Supplier<T> computeIfAbsent)
        Returns the Faces context attribute value associated with the given name, or computes the supplied value if absent.
        Type Parameters:
        T - The expected return type.
        Parameters:
        name - The Faces context attribute name.
        computeIfAbsent - The computed Faces context attribute value when absent. Useful if it represents a collection, map or bean.
        Returns:
        The Faces context attribute value associated with the given name.
        Throws:
        NullPointerException - When faces context is unavailable.
        ClassCastException - When T is of wrong type.
        Since:
        3.1
        See Also:
        ExternalContext.getRequestMap()
      • setContextAttribute

        public static void setContextAttribute​(String name,
                                               Object value)
        Sets the Faces context attribute value associated with the given name.
        Parameters:
        name - The Faces context attribute name.
        value - The Faces context attribute value.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        1.3
        See Also:
        FacesContext.getAttributes()
      • createConverter

        public static <T> Converter<T> createConverter​(Object identifier)
        Creates and returns a Faces converter associated with given object identifier. If the given identifier is an instance of string, then delegate to createConverter(String). If the given identifier is an instance of class, then delegate to createConverter(Class). If the given identifier is a concrete converter instance, then return it directly. If no converter instance can be associated, then return null.
        Type Parameters:
        T - The expected converter type.
        Parameters:
        identifier - The Faces converter object identifier. This can be a string representing the converter ID, or a class representing the target type, or a class representing the converter class, or even the converter instance itself.
        Returns:
        A Faces converter associated with given object identifier.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        2.5
      • createConverter

        public static <T> Converter<T> createConverter​(String identifier)
        Creates and returns a Faces converter associated with given string identifier. First use the identifier as converter ID in Application.createConverter(String). If that didn't return anything, then try to interpret the string identifier as class name and delegate to createConverter(Class). If no converter instance can be associated, then return null.
        Type Parameters:
        T - The expected converter type.
        Parameters:
        identifier - The Faces converter string identifier.
        Returns:
        A Faces converter associated with given string identifier.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        2.5
      • createConverter

        public static <T> Converter<T> createConverter​(Class<?> identifier)
        Creates and returns a Faces converter associated with given class identifier. If the given identifier is not assignable to Converter.class, then use that as target type in Application.createConverter(Class). If the given identifier is assignable to Converter.class, and the FacesConverter annotation is present, then instantiate it using CDI, else instantiate it using default constructor. If no converter instance can be associated, then return null.
        Type Parameters:
        T - The expected converter type.
        Parameters:
        identifier - The Faces converter class identifier.
        Returns:
        A Faces converter associated with given class identifier.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        2.5
      • createValidator

        public static <T> Validator<T> createValidator​(Object identifier)
        Creates and returns a Faces validator associated with given object identifier. If the given identifier is an instance of string, then delegate to createValidator(String). If the given identifier is an instance of class, then delegate to createValidator(Class). If the given identifier is a concrete validator instance, then return it directly. If no validator instance can be associated, then return null.
        Type Parameters:
        T - The expected validator type.
        Parameters:
        identifier - The Faces validator object identifier. This can be a string representing the validator ID, or a class representing the validator class, or even the validator instance itself.
        Returns:
        A Faces validator associated with given object identifier.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        2.5
      • createValidator

        public static <T> Validator<T> createValidator​(String identifier)
        Creates and returns a Faces validator associated with given string identifier. First use the identifier as validator ID in Application.createValidator(String). If that didn't return anything, then try to interpret the string identifier as class name and delegate to createValidator(Class). If no validator instance can be associated, then return null.
        Type Parameters:
        T - The expected validator type.
        Parameters:
        identifier - The Faces validator string identifier.
        Returns:
        A Faces validator associated with given string identifier.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        2.5
      • createValidator

        public static <T> Validator<T> createValidator​(Class<?> identifier)
        Creates and returns a Faces validator associated with given class identifier. If the given identifier is assignable to Validator.class, and the FacesValidator annotation is present, then instantiate it using CDI, else instantiate it using default constructor. If no validator instance can be associated, then return null.
        Type Parameters:
        T - The expected validator type.
        Parameters:
        identifier - The Faces validator class identifier.
        Returns:
        A Faces validator associated with given class identifier.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        2.5
      • createResource

        public static Resource createResource​(String resourceName)
        Creates and returns a Faces resource associated with given resource name. If no resource can be allocated, then return null.
        Parameters:
        resourceName - The resource name.
        Returns:
        A Faces resource associated with given resource name.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        3.6
        See Also:
        ResourceHandler.createResource(String)
      • createResource

        public static Resource createResource​(String libraryName,
                                              String resourceName)
        Creates and returns a Faces resource associated with given library name and resource name. If no resource can be allocated, then return null.
        Parameters:
        libraryName - The library name.
        resourceName - The resource name.
        Returns:
        A Faces resource associated with given library name and resource name.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        3.6
        See Also:
        ResourceHandler.createResource(String, String)
      • createResource

        public static Resource createResource​(ResourceIdentifier resourceIdentifier)
        Creates and returns a Faces resource associated with given resource identifier. If no resource can be allocated, then return null.
        Parameters:
        resourceIdentifier - The resource identifier.
        Returns:
        A Faces resource associated with given resource identifier.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        3.6
        See Also:
        ResourceHandler.createResource(String, String)
      • getViewId

        public static String getViewId()
        Returns the ID of the current view root, or null if there is no view.

        This is also available in EL as #{faces.viewId}, although #{view.viewId} could be used.

        Returns:
        The ID of the current view root, or null if there is no view.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        UIViewRoot.getViewId()
      • getViewName

        public static String getViewName()
        Returns the base name of the current view, without extension, or null if there is no view. E.g. if the view ID is /path/to/some.xhtml, then this will return some.

        This is also available in EL as #{faces.viewName}.

        Returns:
        The base name of the current view, without extension, or null if there is no view.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        2.3
        See Also:
        UIViewRoot.getViewId()
      • getRenderKit

        public static RenderKit getRenderKit()
        Returns the RenderKit associated with the "current" view ID or view handler.

        The current view ID is the view ID that's set for the view root that's associated with the current faces context. Or if there is none, then the current view handler will be assumed, which is the view handler that's associated with the requested view.

        Returns:
        The RenderKit associated with the "current" view ID or view handler.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        2.2
        See Also:
        UIViewRoot.getRenderKitId(), ViewHandler.calculateRenderKitId(FacesContext)
      • normalizeViewId

        public static String normalizeViewId​(String path)
        Normalize the given path as a valid view ID based on the current mapping, if necessary.
        • If the current mapping is a prefix mapping and the given path starts with it, then remove it.
        • If the current mapping is a suffix mapping and the given path ends with it, then replace it with the default Facelets suffix.
        Parameters:
        path - The path to be normalized as a valid view ID based on the current mapping.
        Returns:
        The path as a valid view ID.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        getMapping(), isPrefixMapping(String)
      • getHashParameters

        public static Collection<HashParam> getHashParameters()
        Returns the hash parameters of the current view, or an empty collection if there is no view.
        Returns:
        The hash parameters of the current view, or an empty collection if there is no view.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        3.2
        See Also:
        HashParam
      • getHashParameterMap

        public static Map<String,​List<String>> getHashParameterMap()
        Returns the hash parameters of the current view as a parameter map, or an empty map if there is no view.
        Returns:
        The hash parameters of the current view as a parameter map, or an empty map if there is no view.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        3.2
        See Also:
        HashParam
      • getHashQueryString

        public static String getHashQueryString()
        Returns the hash query string of the current view, or null if there is none. This is the part after the # in the request URL as the enduser sees in browser address bar. This works only if the hash parameters are via <o:hashParam> registered in the view.
        Returns:
        The hash query string of the current view, or null if there is none.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        3.2
        See Also:
        HashParam
      • getScriptParameters

        public static Collection<ScriptParam> getScriptParameters()
        Returns the script parameters of the current view, or an empty collection if there is no view.
        Returns:
        The script parameters of the current view, or an empty collection if there is no view.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        3.6
        See Also:
        ScriptParam
      • getMetadataAttributes

        public static Map<String,​Object> getMetadataAttributes​(String viewId)
        Returns the metadata attribute map of the given view ID, or an empty map if there is no view metadata.
        Parameters:
        viewId - The view ID to return the metadata attribute map for.
        Returns:
        The metadata attribute map of the given view ID, or an empty map if there is no view metadata.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        1.4
        See Also:
        ViewDeclarationLanguage.getViewMetadata(FacesContext, String)
      • getMetadataAttributes

        public static Map<String,​Object> getMetadataAttributes()
        Returns the metadata attribute map of the current view, or an empty map if there is no view metadata.
        Returns:
        The metadata attribute map of the current view, or an empty map if there is no view metadata.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        2.0
        See Also:
        UIComponentBase.getAttributes()
      • getMetadataAttribute

        public static <T> T getMetadataAttribute​(String viewId,
                                                 String name)
        Returns the metadata attribute of the given view ID associated with the given name. Note: this is not the same as the view scope, for that use getViewAttribute(String).
        Type Parameters:
        T - The expected return type.
        Parameters:
        viewId - The view ID to return the metadata attribute for.
        name - The metadata attribute name.
        Returns:
        The metadata attribute of the given view ID associated with the given name.
        Throws:
        NullPointerException - When faces context is unavailable.
        ClassCastException - When T is of wrong type.
        Since:
        1.4
        See Also:
        ViewDeclarationLanguage.getViewMetadata(FacesContext, String)
      • getMetadataAttribute

        public static <T> T getMetadataAttribute​(String name)
        Returns the metadata attribute of the current view associated with the given name. Note: this is not the same as the view scope, for that use getViewAttribute(String).
        Type Parameters:
        T - The expected return type.
        Parameters:
        name - The metadata attribute name.
        Returns:
        The metadata attribute of the current view associated with the given name.
        Throws:
        NullPointerException - When faces context is unavailable.
        ClassCastException - When T is of wrong type.
        Since:
        1.4
        See Also:
        UIComponentBase.getAttributes()
      • getDefaultLocale

        public static Locale getDefaultLocale()
        Returns the default locale, or null if there is none.
        Returns:
        The default locale, or null if there is none.
        See Also:
        Application.getDefaultLocale()
      • setLocale

        public static void setLocale​(Locale locale)
        Set the locale of the current view, which is to be used in localizing of the response.
        Parameters:
        locale - The locale of the current view.
        Throws:
        NullPointerException - When faces context is unavailable.
        IllegalStateException - When there is no view (i.e. when it is null). This can happen if the method is called at the wrong moment in the Faces lifecycle, e.g. before the view has been restored/created.
        Since:
        1.2
        See Also:
        UIViewRoot.setLocale(Locale)
      • getMessageBundle

        public static ResourceBundle getMessageBundle()
        Returns the application message bundle as identified by <message-bundle> in faces-config.xml. The instance is already localized via getLocale(). If there is no <message-bundle>, then this method just returns null.
        Returns:
        The message bundle as identified by <message-bundle> in faces-config.xml.
        Throws:
        NullPointerException - When faces context is unavailable.
        MissingResourceException - When the <message-bundle> in faces-config.xml does not refer an existing resource in the classpath.
        Since:
        2.0
        See Also:
        Application.getMessageBundle()
      • getResourceBundle

        public static ResourceBundle getResourceBundle​(String var)
        Returns the application resource bundle as identified by the given <var> of the <resource-bundle> in faces-config.xml. If there is no <resource-bundle> with the given <var>, then this method just returns null.
        Parameters:
        var - The value of the <var> which identifies the <resource-bundle> in faces-config.xml.
        Returns:
        The application resource bundle as identified by the given <var> of the <resource-bundle> in faces-config.xml.
        Throws:
        NullPointerException - When faces context is unavailable.
        MissingResourceException - When the <resource-bundle> as identified by the given <var> in faces-config.xml does not refer an existing resource in the classpath.
        Since:
        2.0
        See Also:
        Application.getResourceBundle(FacesContext, String)
      • getResourceBundles

        public static Map<String,​ResourceBundle> getResourceBundles()
        Returns all application resource bundles registered as <resource-bundle> in faces-config.xml. If there are no resource bundles registered, then this method just returns an empty map.
        Returns:
        all application resource bundles registered as <resource-bundle> in faces-config.xml. <base-name> of the <resource-bundle> in faces-config.xml.
        Throws:
        NullPointerException - When faces context is unavailable.
        MissingResourceException - When the <resource-bundle> in faces-config.xml does not refer an existing resource in the classpath.
        Since:
        2.1
        See Also:
        Application.getResourceBundle(FacesContext, String)
      • getBundleString

        public static String getBundleString​(String key)
        Gets a string for the given key searching declared resource bundles, order by declaration in faces-config.xml. If the string is missing, then this method returns ???key???.
        Parameters:
        key - The bundle key.
        Returns:
        a string for the given key searching declared resource bundles, order by declaration in faces-config.xml.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        2.1
      • getBookmarkableURL

        public static String getBookmarkableURL​(Map<String,​List<String>> params,
                                                boolean includeViewParams)
        Returns the concrete domain-relative URL to the current view with the given params URL-encoded in the query string and optionally include view parameters as well. This URL can ultimately be used as redirect URL, or in <form action>, or in <a href>. Any parameter with an empty name or value will be skipped. To skip empty view parameters as well, use <o:viewParam> instead.
        Parameters:
        params - The parameters to be URL-encoded in the query string. Can be null.
        includeViewParams - Whether the view parameters of the current view should be included as well.
        Returns:
        The concrete domain-relative URL to the current view.
        Throws:
        NullPointerException - When faces context is unavailable.
        IllegalStateException - When there is no view (i.e. when it is null). This can happen if the method is called at the wrong moment in the Faces lifecycle, e.g. before the view has been restored/created.
        Since:
        1.6
        See Also:
        ViewHandler.getBookmarkableURL(FacesContext, String, Map, boolean)
      • getBookmarkableURL

        public static String getBookmarkableURL​(String viewId,
                                                Map<String,​List<String>> params,
                                                boolean includeViewParams)
        Returns the concrete domain-relative URL to the given view with the given params URL-encoded in the query string and optionally include view parameters as well. This URL can ultimately be used as redirect URL, or in <form action>, or in <a href>. Any parameter with an empty name or value will be skipped. To skip empty view parameters as well, use <o:viewParam> instead.
        Parameters:
        viewId - The view ID to create the bookmarkable URL for.
        params - The parameters to be URL-encoded in the query string. Can be null.
        includeViewParams - Whether the view parameters of the current view which are also declared in the target view should be included as well. Note thus that this does not include the view parameters which are not declared in the target view!
        Returns:
        The concrete domain-relative URL to the target view.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        1.6
        See Also:
        ViewHandler.getBookmarkableURL(FacesContext, String, Map, boolean)
      • getBookmarkableURL

        public static String getBookmarkableURL​(Collection<? extends ParamHolder<?>> params,
                                                boolean includeViewParams)
        Returns the concrete domain-relative URL to the current view with the given params URL-encoded in the query string and optionally include view parameters as well. This URL can ultimately be used as redirect URL, or in <form action>, or in <a href>. Any parameter with an empty name or value will be skipped. To skip empty view parameters as well, use <o:viewParam> instead.
        Parameters:
        params - The parameters to be URL-encoded in the query string. Can be null.
        includeViewParams - Whether the view parameters of the current view should be included as well.
        Returns:
        The concrete domain-relative URL to the current view.
        Throws:
        NullPointerException - When faces context is unavailable.
        IllegalStateException - When there is no view (i.e. when it is null). This can happen if the method is called at the wrong moment in the Faces lifecycle, e.g. before the view has been restored/created.
        Since:
        1.7
        See Also:
        ViewHandler.getBookmarkableURL(FacesContext, String, Map, boolean)
      • getBookmarkableURL

        public static String getBookmarkableURL​(String viewId,
                                                Collection<? extends ParamHolder<?>> params,
                                                boolean includeViewParams)
        Returns the concrete domain-relative URL to the given view with the given params URL-encoded in the query string and optionally include view parameters as well. This URL can ultimately be used as redirect URL, or in <form action>, or in <a href>. Any parameter with an empty name or value will be skipped. To skip empty view parameters as well, use <o:viewParam> instead.
        Parameters:
        viewId - The view ID to create the bookmarkable URL for.
        params - The parameters to be URL-encoded in the query string. Can be null.
        includeViewParams - Whether the view parameters of the current view which are also declared in the target view should be included as well. Note thus that this does not include the view parameters which are not declared in the target view!
        Returns:
        The concrete domain-relative URL to the target view.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        1.7
        See Also:
        ViewHandler.getBookmarkableURL(FacesContext, String, Map, boolean)
      • getFaceletContext

        public static FaceletContext getFaceletContext()
        Returns the Facelet context.

        Note that whenever you absolutely need this method to perform a general task, you might want to consider to submit a feature request to OmniFaces in order to add a new utility method which performs exactly this general task.

        Returns:
        The Facelet context.
        Throws:
        NullPointerException - When faces context is unavailable.
        IllegalStateException - When the Facelet context is not available.
        Since:
        1.1
        See Also:
        FaceletContext
      • getFaceletAttribute

        public static <T> T getFaceletAttribute​(String name)
        Returns the Facelet attribute value associated with the given name. This basically returns the value of the <ui:param> which is been declared inside the Facelet file, or is been passed into the Facelet file by e.g. an <ui:include>.
        Type Parameters:
        T - The expected return type.
        Parameters:
        name - The Facelet attribute name.
        Returns:
        The Facelet attribute value associated with the given name.
        Throws:
        NullPointerException - When faces context is unavailable.
        IllegalStateException - When the Facelet context is not available.
        ClassCastException - When T is of wrong type.
        Since:
        1.1
        See Also:
        FaceletContext.getAttribute(String)
      • setFaceletAttribute

        public static void setFaceletAttribute​(String name,
                                               Object value)
        Sets the Facelet attribute value associated with the given name. This basically does the same as an <ui:param> which is been declared inside the Facelet file, or is been passed into the Facelet file by e.g. an <ui:include>.
        Parameters:
        name - The Facelet attribute name.
        value - The Facelet attribute value.
        Throws:
        NullPointerException - When faces context is unavailable.
        IllegalStateException - When the Facelet context is not available.
        Since:
        1.1
        See Also:
        FaceletContext.setAttribute(String, Object)
      • getRequest

        public static HttpServletRequest getRequest()
        Returns the HTTP servlet request.

        Note that whenever you absolutely need this method to perform a general task, you might want to consider to submit a feature request to OmniFaces in order to add a new utility method which performs exactly this general task.

        Returns:
        The HTTP servlet request.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        ExternalContext.getRequest()
      • isAjaxRequest

        public static boolean isAjaxRequest()
        Returns whether the current request is an ajax request.

        This is also available in EL as #{faces.ajaxRequest}.

        Returns:
        true for an ajax request, false for a non-ajax (synchronous) request.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        PartialViewContext.isAjaxRequest()
      • isAjaxRequestWithPartialRendering

        public static boolean isAjaxRequestWithPartialRendering()
        Returns whether the current request is an ajax request with partial rendering. That is, when it's an ajax request without render="@all".

        This is also available in EL as #{faces.ajaxRequestWithPartialRendering}.

        Returns:
        true for an ajax request with partial rendering, false an ajax request with render="@all" or a non-ajax (synchronous) request.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        2.3
        See Also:
        PartialViewContext.isAjaxRequest(), PartialViewContext.isRenderAll()
      • isPostback

        public static boolean isPostback()
        Returns whether the current request is a postback. This not only delegates to FacesContext.isPostback() which checks the presence of jakarta.faces.ViewState request parameter, but this also explicitly checks the HTTP request method. So this should exclude GET requests having a jakarta.faces.ViewState request parameter in query string.

        This is also available in EL as #{faces.postback}.

        Returns:
        true for a postback, false for a non-postback (GET) request.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        FacesContext.isPostback()
      • getRequestParameter

        public static String getRequestParameter​(String name)
        Returns the HTTP request parameter value associated with the given name.
        Parameters:
        name - The HTTP request parameter name.
        Returns:
        The HTTP request parameter value associated with the given name.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        ExternalContext.getRequestParameterMap()
      • getRequestParameter

        public static <T> T getRequestParameter​(String name,
                                                Class<T> type)
        Returns the HTTP request parameter value associated with the given name and implicitly converted to given type using the Faces converter registered by forClass on the given type. Note that empty strings are already implicitly converted to null.
        Type Parameters:
        T - The expected return type.
        Parameters:
        name - The HTTP request parameter name.
        type - The converter forClass type.
        Returns:
        The HTTP request parameter value associated with the given name and implicitly converted to given type.
        Throws:
        NullPointerException - When faces context is unavailable.
        ConverterException - When conversion fails.
        ClassCastException - When T is of wrong type.
        Since:
        2.6
        See Also:
        ExternalContext.getRequestParameterMap(), createConverter(Class)
      • getRequestParameter

        public static <T> T getRequestParameter​(String name,
                                                Function<String,​T> converter)
        Returns the HTTP request parameter value associated with the given name and converted using the given converter. Note that empty strings are already implicitly converted to null.
        Type Parameters:
        T - The expected return type.
        Parameters:
        name - The HTTP request parameter name.
        converter - The converter.
        Returns:
        The HTTP request parameter value associated with the given name and converted using the given converter.
        Throws:
        NullPointerException - When faces context is unavailable or given converter is null.
        ClassCastException - When T is of wrong type.
        Since:
        3.10
        See Also:
        ExternalContext.getRequestParameterMap()
      • getRequestParameter

        public static <T> T getRequestParameter​(String name,
                                                Function<String,​T> converter,
                                                Supplier<T> defaultValue)
        Returns the HTTP request parameter value associated with the given name and convert it using the given converter, or else the supplied value if absent. Note that empty strings are already implicitly converted to null.
        Type Parameters:
        T - The expected return type.
        Parameters:
        name - The HTTP request parameter name.
        converter - The converter.
        defaultValue - The default request parameter value when absent.
        Returns:
        The HTTP request parameter value associated with the given name and convert it using the given converter, or else the supplied value if absent.
        Throws:
        ClassCastException - When T is of wrong type.
        NullPointerException - When faces context is unavailable or given converter or supplier is null.
        Since:
        3.10
        See Also:
        ExternalContext.getRequestParameterMap()
      • getRequestParameterValues

        public static String[] getRequestParameterValues​(String name)
        Returns the HTTP request parameter values associated with the given name.
        Parameters:
        name - The HTTP request parameter name.
        Returns:
        The HTTP request parameter values associated with the given name.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        ExternalContext.getRequestParameterValuesMap()
      • getRequestParameterValues

        public static <T> T[] getRequestParameterValues​(String name,
                                                        Class<T> type)
        Returns the HTTP request parameter values associated with the given name and implicitly convert it to given type using the Faces converter registered by forClass on the given type.
        Type Parameters:
        T - The expected return type.
        Parameters:
        name - The HTTP request parameter name.
        type - The converter forClass type.
        Returns:
        The HTTP request parameter values associated with the given name and implicitly convert it to given type.
        Throws:
        NullPointerException - When faces context is unavailable.
        ConverterException - When conversion fails.
        ClassCastException - When T is of wrong type.
        Since:
        2.6
        See Also:
        ExternalContext.getRequestParameterValuesMap(), createConverter(Class)
      • getRequestParts

        public static Collection<Part> getRequestParts()
        Returns all HTTP request parts, provided that request is of type multipart/form-data. If there are no parts, an empty collection is returned.
        Returns:
        all HTTP request parts.
        Throws:
        NullPointerException - When faces context is unavailable.
        FacesException - Whenever something fails at servlet or I/O level. The caller should preferably not catch it, but just let it go. The servletcontainer will handle it.
        Since:
        2.5
        See Also:
        HttpServletRequest.getParts()
      • getRequestPart

        public static Part getRequestPart​(String name)
        Returns the HTTP request part associated with the given name, else return null.
        Parameters:
        name - The HTTP request part name.
        Returns:
        The HTTP request part associated with the given name.
        Throws:
        NullPointerException - When faces context is unavailable.
        FacesException - Whenever something fails at servlet or I/O level. The caller should preferably not catch it, but just let it go. The servletcontainer will handle it.
        Since:
        2.5
        See Also:
        HttpServletRequest.getPart(String)
      • getRequestParts

        public static Collection<Part> getRequestParts​(String name)
        Returns all HTTP request parts associated with the given name, provided that request is of type multipart/form-data. If there are no parts, an empty collection is returned.
        Parameters:
        name - The HTTP request part name.
        Returns:
        All HTTP request parts associated with the given name.
        Throws:
        NullPointerException - When faces context is unavailable.
        FacesException - Whenever something fails at servlet or I/O level. The caller should preferably not catch it, but just let it go. The servletcontainer will handle it.
        Since:
        2.5
        See Also:
        HttpServletRequest.getParts()
      • getRequestHeader

        public static String getRequestHeader​(String name)
        Returns the HTTP request header value associated with the given name.
        Parameters:
        name - The HTTP request header name.
        Returns:
        The HTTP request header value associated with the given name.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        ExternalContext.getRequestHeaderMap()
      • getRequestHeaderValues

        public static String[] getRequestHeaderValues​(String name)
        Returns the HTTP request header values associated with the given name.
        Parameters:
        name - The HTTP request header name.
        Returns:
        The HTTP request header values associated with the given name.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        ExternalContext.getRequestHeaderValuesMap()
      • getRequestContextPath

        public static String getRequestContextPath()
        Returns the HTTP request context path. It's the webapp context name, with a leading slash. If the webapp runs on context root, then it returns an empty string.

        This is also available in EL as #{faces.requestContextPath}.

        Returns:
        The HTTP request context path.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        ExternalContext.getRequestContextPath()
      • getRequestServletPath

        public static String getRequestServletPath()
        Returns the HTTP request servlet path. If Faces is prefix mapped (e.g. /faces/*), then this returns the whole prefix mapping (e.g. /faces). If Faces is suffix mapped (e.g. *.xhtml), then this returns the whole part after the context path, with a leading slash.

        This is also available in EL as #{faces.requestServletPath}.

        Returns:
        The HTTP request servlet path.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        ExternalContext.getRequestServletPath()
      • getRequestPathInfo

        public static String getRequestPathInfo()
        Returns the HTTP request path info, taking into account whether FacesViews is used with MultiViews enabled. If the resource is prefix mapped (e.g. /faces/*), then this returns the whole part after the prefix mapping, with a leading slash. If the resource is suffix mapped (e.g. *.xhtml), then this returns null. If MultiViews is enabled, then this returns the part after the mapped view, if any.

        This is also available in EL as #{faces.requestPathInfo}.

        Returns:
        The HTTP request path info.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        ExternalContext.getRequestPathInfo(), FacesViews.FACES_VIEWS_ORIGINAL_PATH_INFO
      • getRequestHostname

        public static String getRequestHostname()
        Returns the HTTP request hostname. This is the entire domain, without any scheme and slashes. Noted should be that this value is extracted from the request URL, not from ServletRequest.getServerName() as its outcome can be influenced by proxies.

        This is also available in EL as #{faces.requestHostName}.

        Returns:
        The HTTP request hostname.
        Throws:
        NullPointerException - When faces context is unavailable.
        IllegalArgumentException - When the URL is malformed. This is however unexpected as the request would otherwise not have hit the server at all.
        Since:
        1.6
        See Also:
        HttpServletRequest.getRequestURL()
      • getRequestURL

        public static String getRequestURL()
        Returns the HTTP request URL. This is the full request URL as the enduser sees in browser address bar. This does not include the request query string.

        This is also available in EL as #{faces.requestURL}.

        Returns:
        The HTTP request URL.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        1.1
        See Also:
        HttpServletRequest.getRequestURL()
      • getRequestURI

        public static String getRequestURI()
        Returns the HTTP request URI. This is the part after the domain in the request URL, including the leading slash. This does not include the request query string.

        This is also available in EL as #{faces.requestURI}.

        Returns:
        The HTTP request URI.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        1.1
        See Also:
        HttpServletRequest.getRequestURI()
      • getRequestQueryString

        public static String getRequestQueryString()
        Returns the HTTP request query string. This is the part after the ? in the request URL as the enduser sees in browser address bar.

        This is also available in EL as #{faces.requestQueryString}.

        Returns:
        The HTTP request query string.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        1.1
        See Also:
        HttpServletRequest.getQueryString()
      • getRequestURLWithQueryString

        public static String getRequestURLWithQueryString()
        Returns the HTTP request URL with query string. This is the full request URL with query string as the enduser sees in browser address bar.

        This is also available in EL as #{faces.requestURLWithQueryString}.

        Returns:
        The HTTP request URL with query string.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        1.5
        See Also:
        HttpServletRequest.getRequestURL(), HttpServletRequest.getQueryString()
      • getRequestURIWithQueryString

        public static String getRequestURIWithQueryString()
        Returns the HTTP request URI with query string. This is the part after the domain in the request URL, including the leading slash and the request query string.

        This is also available in EL as #{faces.requestURIWithQueryString}.

        Returns:
        The HTTP request URI with query string.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        1.6
        See Also:
        HttpServletRequest.getRequestURI(), HttpServletRequest.getQueryString()
      • getRemoteAddr

        public static String getRemoteAddr()
        Returns the Internet Protocol (IP) address of the client that sent the request. This will first check the X-Forwarded-For request header and if it's present, then return its first IP address, else just return ServletRequest.getRemoteAddr() unmodified.

        This is also available in EL as #{faces.remoteAddr}.

        Returns:
        The IP address of the client.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        1.2
        See Also:
        ServletRequest.getRemoteAddr()
      • getUserAgent

        public static String getUserAgent()
        Returns the User-Agent string of the client.

        This is also available in EL as #{faces.userAgent}.

        Returns:
        The User-Agent string of the client.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        3.2
        See Also:
        HttpServletRequest.getHeader(String)
      • isRequestSecure

        public static boolean isRequestSecure()
        Returns true if connection is secure, false otherwise. This method will first check if ServletRequest.isSecure() returns true, and if not true, check if the X-Forwarded-Proto is present and equals to https.
        Returns:
        true if connection is secure, false otherwise.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        3.0
        See Also:
        ServletRequest.isSecure()
      • getResponse

        public static HttpServletResponse getResponse()
        Returns the HTTP servlet response.

        Note that whenever you absolutely need this method to perform a general task, you might want to consider to submit a feature request to OmniFaces in order to add a new utility method which performs exactly this general task.

        Returns:
        The HTTP servlet response.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        ExternalContext.getResponse()
      • getResponseBufferSize

        public static int getResponseBufferSize()
        Returns the HTTP response buffer size. If Facelets is used and the jakarta.faces.FACELETS_BUFFER_SIZE context parameter is been set, then it's the context parameter value which will be returned. Otherwise it returns the implementation independent default value, which is 1024 in Mojarra.
        Returns:
        The HTTP response buffer size.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        1.2
        See Also:
        ExternalContext.getResponseBufferSize()
      • setResponseStatus

        public static void setResponseStatus​(int status)
        Sets the HTTP response status code. You can use the constant field values of HttpServletResponse for this. For example, Faces.setResponseStatus(HttpServletResponse.SC_BAD_REQUEST).
        Parameters:
        status - The HTTP status code to be set on the current response.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        1.6
      • redirect

        public static void redirect​(String url,
                                    Object... paramValues)
        Sends a temporary (302) redirect to the given URL. If the given URL does not start with http://, https:// or /, then the request context path will be prepended, otherwise it will be the unmodified redirect URL. So, when redirecting to another page in the same web application, always specify the full path from the context root on (which in turn does not need to start with /).
         Faces.redirect("other.xhtml");
         

        You can use String.format(String, Object...) placeholder %s in the redirect URL to represent placeholders for any request parameter values which needs to be URL-encoded. Here's a concrete example:

         Faces.redirect("other.xhtml?foo=%s&bar=%s", foo, bar);
         
        Parameters:
        url - The URL to redirect the current response to.
        paramValues - The request parameter values which you'd like to put URL-encoded in the given URL.
        Throws:
        NullPointerException - When faces context is unavailable or given url is null.
        UncheckedIOException - When HTTP response is not available anymore.
        See Also:
        ExternalContext.redirect(String)
      • redirectPermanent

        public static void redirectPermanent​(String url,
                                             Object... paramValues)
        Sends a permanent (301) redirect to the given URL. If the given URL does not start with http://, https:// or /, then the request context path will be prepended, otherwise it will be the unmodified redirect URL. So, when redirecting to another page in the same web application, always specify the full path from the context root on (which in turn does not need to start with /).
         Faces.redirectPermanent("other.xhtml");
         

        You can use String.format(String, Object...) placeholder %s in the redirect URL to represent placeholders for any request parameter values which needs to be URL-encoded. Here's a concrete example:

         Faces.redirectPermanent("other.xhtml?foo=%s&bar=%s", foo, bar);
         

        This method does by design not work on ajax requests. It is not possible to return a "permanent redirect" via Faces ajax XML response.

        Parameters:
        url - The URL to redirect the current response to.
        paramValues - The request parameter values which you'd like to put URL-encoded in the given URL.
        Throws:
        NullPointerException - When faces context is unavailable or given url is null.
        See Also:
        ExternalContext.setResponseStatus(int), ExternalContext.setResponseHeader(String, String)
      • responseSendError

        public static void responseSendError​(int status,
                                             String message)
        Sends a HTTP response error with the given status and message. This will end up in either a custom <error-page> whose <error-code> matches the given status, or in a servlet container specific default error page if there is none. The message will be available in the error page as a request attribute with name jakarta.servlet.error.message. The FacesContext.responseComplete() will implicitly be called after sending the error.
        Parameters:
        status - The HTTP response status which is supposed to be in the range 4nn-5nn. You can use the constant field values of HttpServletResponse for this.
        message - The message which is supposed to be available in the error page.
        Throws:
        NullPointerException - When faces context is unavailable.
        UncheckedIOException - When HTTP response is not available anymore.
        See Also:
        ExternalContext.responseSendError(int, String)
      • isResponseCommitted

        public static boolean isResponseCommitted()
        Returns whether the response is already committed. That is, when the response headers and a part of the response body has already been sent to the client. This is usually a point of no return and you can't change the response anymore.
        Returns:
        true if the response is already committed, otherwise false.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        1.1
        See Also:
        ExternalContext.isResponseCommitted()
      • responseReset

        public static void responseReset()
        Resets the current response. This will clear any headers which are been set and any data which is written to the response buffer which isn't committed yet.
        Throws:
        NullPointerException - When faces context is unavailable.
        IllegalStateException - When the response is already committed.
        Since:
        1.1
        See Also:
        ExternalContext.responseReset()
      • renderResponse

        public static void renderResponse()
        Signals Faces that, as soon as the current phase of the lifecycle has been completed, control should be passed to the Render Response phase, bypassing any phases that have not been executed yet.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        1.4
        See Also:
        FacesContext.renderResponse()
      • isRenderResponse

        public static boolean isRenderResponse()
        Returns true if we're currently in the render response phase. This explicitly checks the current phase ID instead of FacesContext.getRenderResponse() as the latter may unexpectedly return false during a GET request when <f:viewParam> is been used.

        This is also available in EL as #{faces.renderResponse}.

        Returns:
        true if we're currently in the render response phase.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        1.4
        See Also:
        FacesContext.getCurrentPhaseId()
      • responseComplete

        public static void responseComplete()
        Signals Faces that the response for this request has already been generated (such as providing a file download), and that the lifecycle should be terminated as soon as the current phase is completed.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        1.4
        See Also:
        FacesContext.responseComplete()
      • login

        public static void login​(String username,
                                 String password)
                          throws ServletException
        Perform programmatic login for container managed FORM based authentication. Note that configuration is container specific and unrelated to Faces. Refer the documentation of the servletcontainer using the keyword "realm".
        Parameters:
        username - The login username.
        password - The login password.
        Throws:
        NullPointerException - When faces context is unavailable.
        ServletException - When the login is invalid, or when container managed FORM based authentication is not enabled.
        See Also:
        HttpServletRequest.login(String, String)
      • authenticate

        public static boolean authenticate()
                                    throws ServletException
        Trigger the default container managed authentication mechanism on the current request. It expects the username and password being available as predefinied request parameters on the current request and/or a custom JASPIC implementation.
        Returns:
        true if the authentication was successful, otherwise false.
        Throws:
        NullPointerException - When faces context is unavailable.
        ServletException - When the authentication has failed. The caller is responsible for handling it.
        UncheckedIOException - When HTTP request or response is not available anymore.
        Since:
        1.4
        See Also:
        HttpServletRequest.authenticate(HttpServletResponse)
      • getRemoteUser

        public static String getRemoteUser()
        Returns the name of the logged-in user for container managed FORM based authentication, if any.

        This is also available in EL as #{faces.remoteUser}.

        Returns:
        The name of the logged-in user for container managed FORM based authentication, if any.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        ExternalContext.getRemoteUser()
      • isUserInRole

        public static boolean isUserInRole​(String role)
        Returns whether the currently logged-in user has the given role.
        Parameters:
        role - The role to be checked on the currently logged-in user.
        Returns:
        true if the currently logged-in user has the given role, otherwise false.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        ExternalContext.isUserInRole(String)
      • getRequestCookie

        public static String getRequestCookie​(String name)
        Returns the value of the HTTP request cookie associated with the given name. The value is implicitly URL-decoded with a charset of UTF-8.
        Parameters:
        name - The HTTP request cookie name.
        Returns:
        The value of the HTTP request cookie associated with the given name.
        Throws:
        NullPointerException - When faces context is unavailable.
        UnsupportedOperationException - When this platform does not support UTF-8.
        See Also:
        ExternalContext.getRequestCookieMap()
      • addResponseCookie

        public static void addResponseCookie​(String name,
                                             String value,
                                             int maxAge)
        Add a cookie with given name, value and maxage to the HTTP response. The cookie value will implicitly be URL-encoded with UTF-8 so that any special characters can be stored. The cookie will implicitly be set in the domain and path of the current request URL. The cookie will implicitly be set to HttpOnly as JavaScript is not supposed to manipulate server-created cookies. The cookie will implicitly be set to secure when the current request is a HTTPS request.
        Parameters:
        name - The cookie name.
        value - The cookie value.
        maxAge - The maximum age of the cookie, in seconds. If this is 0, then the cookie will be removed. Note that the name and path must be exactly the same as it was when the cookie was created. If this is -1 then the cookie will become a session cookie and thus live as long as the established HTTP session.
        Throws:
        NullPointerException - When faces context is unavailable.
        UnsupportedOperationException - When this platform does not support UTF-8.
        Since:
        1.8
        See Also:
        ExternalContext.addResponseCookie(String, String, Map)
      • addResponseCookie

        public static void addResponseCookie​(String name,
                                             String value,
                                             String path,
                                             int maxAge)
        Add a cookie with given name, value, path and maxage to the HTTP response. The cookie value will implicitly be URL-encoded with UTF-8 so that any special characters can be stored. The cookie will implicitly be set in the domain of the current request URL. The cookie will implicitly be set to HttpOnly as JavaScript is not supposed to manipulate server-created cookies. The cookie will implicitly be set to secure when the current request is a HTTPS request.
        Parameters:
        name - The cookie name.
        value - The cookie value.
        path - The cookie path. If this is /, then the cookie is available in all pages of the webapp. If this is /somespecificpath, then the cookie is only available in pages under the specified path.
        maxAge - The maximum age of the cookie, in seconds. If this is 0, then the cookie will be removed. Note that the name and path must be exactly the same as it was when the cookie was created. If this is -1 then the cookie will become a session cookie and thus live as long as the established HTTP session.
        Throws:
        NullPointerException - When faces context is unavailable.
        UnsupportedOperationException - When this platform does not support UTF-8.
        See Also:
        ExternalContext.addResponseCookie(String, String, Map)
      • addResponseCookie

        public static void addResponseCookie​(String name,
                                             String value,
                                             String domain,
                                             String path,
                                             int maxAge)
        Add a cookie with given name, value, domain, path and maxage to the HTTP response. The cookie value will implicitly be URL-encoded with UTF-8 so that any special characters can be stored. The cookie will implicitly be set to HttpOnly as JavaScript is not supposed to manipulate server-created cookies. The cookie will implicitly be set to secure when the current request is a HTTPS request.
        Parameters:
        name - The cookie name.
        value - The cookie value.
        domain - The cookie domain. You can use .example.com (with a leading period) if you'd like the cookie to be available to all subdomains of the domain. Note that you cannot set it to a different domain. Defaults to getRequestHostname() when null.
        path - The cookie path. If this is /, then the cookie is available in all pages of the webapp. If this is /somespecificpath, then the cookie is only available in pages under the specified path.
        maxAge - The maximum age of the cookie, in seconds. If this is 0, then the cookie will be removed. Note that the name and path must be exactly the same as it was when the cookie was created. If this is -1 then the cookie will become a session cookie and thus live as long as the established HTTP session.
        Throws:
        NullPointerException - When faces context is unavailable.
        UnsupportedOperationException - When this platform does not support UTF-8.
        Since:
        1.8
        See Also:
        ExternalContext.addResponseCookie(String, String, Map)
      • addResponseCookie

        public static void addResponseCookie​(String name,
                                             String value,
                                             String domain,
                                             String path,
                                             int maxAge,
                                             boolean httpOnly)
        Add a cookie with given name, value, domain, path, maxage and HttpOnly flag to the HTTP response. The cookie value will implicitly be URL-encoded with UTF-8 so that any special characters can be stored. The cookie will implicitly be set to secure when the current request is a HTTPS request.
        Parameters:
        name - The cookie name.
        value - The cookie value.
        domain - The cookie domain. You can use .example.com (with a leading period) if you'd like the cookie to be available to all subdomains of the domain. Note that you cannot set it to a different domain. Defaults to getRequestHostname() when null.
        path - The cookie path. If this is /, then the cookie is available in all pages of the webapp. If this is /somespecificpath, then the cookie is only available in pages under the specified path.
        maxAge - The maximum age of the cookie, in seconds. If this is 0, then the cookie will be removed. Note that the name and path must be exactly the same as it was when the cookie was created. If this is -1 then the cookie will become a session cookie and thus live as long as the established HTTP session.
        httpOnly - When set to true, then JavaScript is not allowed to manipulate the cookie.
        Throws:
        NullPointerException - When faces context is unavailable.
        UnsupportedOperationException - When this platform does not support UTF-8.
        Since:
        3.3
        See Also:
        ExternalContext.addResponseCookie(String, String, Map)
      • addResponseCookie

        public static void addResponseCookie​(String name,
                                             String value,
                                             String domain,
                                             String path,
                                             int maxAge,
                                             boolean httpOnly,
                                             Map<String,​String> attributes)
        Add a cookie with given name, value, domain, path, maxage, HttpOnly flag and custom attributes to the HTTP response. The cookie value will implicitly be URL-encoded with UTF-8 so that any special characters can be stored. The cookie will implicitly be set to secure when the current request is a HTTPS request.
        Parameters:
        name - The cookie name.
        value - The cookie value.
        domain - The cookie domain. You can use .example.com (with a leading period) if you'd like the cookie to be available to all subdomains of the domain. Note that you cannot set it to a different domain. Defaults to getRequestHostname() when null.
        path - The cookie path. If this is /, then the cookie is available in all pages of the webapp. If this is /somespecificpath, then the cookie is only available in pages under the specified path.
        maxAge - The maximum age of the cookie, in seconds. If this is 0, then the cookie will be removed. Note that the name and path must be exactly the same as it was when the cookie was created. If this is -1 then the cookie will become a session cookie and thus live as long as the established HTTP session.
        httpOnly - When set to true, then JavaScript is not allowed to manipulate the cookie.
        attributes - Any custom attributes you'd like to add to the cookie, such as SameSite:None. Any key whose name matches a predefined cookie attribute name, such as domain, path, HttpOnly, etc, will override them. If the underlying Faces and/or Servlet implementation does not allow a certain custom attribute, then it will throw IllegalArgumentException.
        Throws:
        NullPointerException - When faces context is unavailable.
        UnsupportedOperationException - When this platform does not support UTF-8.
        IllegalArgumentException - When a custom attribute is specified which is not supported by the underlying Faces and/or Servlet implementation. As of now, it's only supported when running minimally Faces 4 on on top of minimally Servlet 6.
        Since:
        4.0
        See Also:
        ExternalContext.addResponseCookie(String, String, Map)
      • removeResponseCookie

        public static void removeResponseCookie​(String name,
                                                String path)
        Remove the cookie with given name and path from the HTTP response. Note that the name and path must be exactly the same as it was when the cookie was created.
        Parameters:
        name - The cookie name.
        path - The cookie path.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        ExternalContext.addResponseCookie(String, String, Map)
      • getSession

        public static HttpSession getSession()
        Returns the HTTP session and creates one if one doesn't exist.

        Note that whenever you absolutely need this method to perform a general task, you might want to consider to submit a feature request to OmniFaces in order to add a new utility method which performs exactly this general task.

        Returns:
        The HTTP session.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        ExternalContext.getSession(boolean)
      • getSession

        public static HttpSession getSession​(boolean create)
        Returns the HTTP session and creates one if one doesn't exist and create argument is true, otherwise don't create one and return null.

        Note that whenever you absolutely need this method to perform a general task, you might want to consider to submit a feature request to OmniFaces in order to add a new utility method which performs exactly this general task.

        Parameters:
        create - Whether or not to create a new session if one doesn't exist.
        Returns:
        The HTTP session.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        ExternalContext.getSession(boolean)
      • getSessionId

        public static String getSessionId()
        Returns a string containing the unique identifier assigned to this session. The identifier is assigned by the servlet container and is implementation dependent.
        Returns:
        The HTTP session ID.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        1.2
        See Also:
        HttpSession.getId()
      • invalidateSession

        public static void invalidateSession()
        Invalidates the current HTTP session. So, any subsequent HTTP request will get a new one when necessary.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        ExternalContext.invalidateSession()
      • hasSession

        public static boolean hasSession()
        Returns whether the HTTP session has already been created.
        Returns:
        true if the HTTP session has already been created, otherwise false.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        1.1
        See Also:
        ExternalContext.getSession(boolean)
      • isSessionNew

        public static boolean isSessionNew()
        Returns whether the HTTP session has been created for the first time in the current request. This returns also false when there is no means of a HTTP session.
        Returns:
        true if the HTTP session has been created for the first time in the current request, otherwise false.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        1.1
        See Also:
        ExternalContext.getSession(boolean), HttpSession.isNew()
      • getSessionCreationTime

        public static long getSessionCreationTime()
        Returns the time when the HTTP session was created, measured in epoch time. This implicitly creates the session if one doesn't exist.
        Returns:
        The time when the HTTP session was created.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        1.1
        See Also:
        HttpSession.getCreationTime()
      • getSessionLastAccessedTime

        public static long getSessionLastAccessedTime()
        Returns the time of the previous request associated with the current HTTP session, measured in epoch time. This implicitly creates the session if one doesn't exist.
        Returns:
        The time of the previous request associated with the current HTTP session.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        1.1
        See Also:
        HttpSession.getLastAccessedTime()
      • getSessionMaxInactiveInterval

        public static int getSessionMaxInactiveInterval()
        Returns the HTTP session timeout in seconds. This implicitly creates the session if one doesn't exist.
        Returns:
        The HTTP session timeout in seconds.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        1.1
        See Also:
        ExternalContext.getSessionMaxInactiveInterval()
      • setSessionMaxInactiveInterval

        public static void setSessionMaxInactiveInterval​(int seconds)
        Sets the HTTP session timeout in seconds. A value of 0 or less means that the session should never timeout. This implicitly creates the session if one doesn't exist.
        Parameters:
        seconds - The HTTP session timeout in seconds.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        1.1
        See Also:
        ExternalContext.setSessionMaxInactiveInterval(int)
      • hasSessionTimedOut

        public static boolean hasSessionTimedOut()
        Returns whether the HTTP session has been timed out for the current request. This is helpful if you need to distinguish between a first-time request on a fresh session and a first-time request on a timed out session, for example to display "Oops, you have been logged out because your session has been timed out!".
        Returns:
        true if the HTTP session has been timed out for the current request, otherwise false.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        1.1
        See Also:
        HttpServletRequest.getRequestedSessionId(), HttpServletRequest.isRequestedSessionIdValid()
      • getServletContext

        public static ServletContext getServletContext()
        Returns the servlet context.

        Note that whenever you absolutely need this method to perform a general task, you might want to consider to submit a feature request to OmniFaces in order to add a new utility method which performs exactly this general task.

        Returns:
        the servlet context.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        ExternalContext.getContext()
      • getInitParameterMap

        public static Map<String,​String> getInitParameterMap()
        Returns the application initialization parameter map. This returns the parameter name-value pairs of all <context-param> entries in in web.xml.
        Returns:
        The application initialization parameter map.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        1.1
        See Also:
        ExternalContext.getInitParameterMap()
      • getInitParameter

        public static String getInitParameter​(String name)
        Returns the application initialization parameter. This returns the <param-value> of a <context-param> in web.xml associated with the given <param-name>.
        Parameters:
        name - The application initialization parameter name.
        Returns:
        The application initialization parameter value associated with the given name, or null if there is none.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        1.1
        See Also:
        ExternalContext.getInitParameter(String)
      • getInitParameterOrDefault

        public static String getInitParameterOrDefault​(String name,
                                                       String defaultValue)
        Returns the application initialization parameter. This returns the <param-value> of a <context-param> in web.xml associated with the given <param-name>.
        Parameters:
        name - The application initialization parameter name.
        defaultValue - The default value if there is no application initialization parameter value associated with the given name.
        Returns:
        The application initialization parameter value associated with the given name, or defaultValue if there is none.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        3.1
        See Also:
        ExternalContext.getInitParameter(String)
      • getMimeType

        public static String getMimeType​(String name)
        Returns the mime type for the given file name. The mime type is determined based on file extension and configureable by <mime-mapping> entries in web.xml. When the mime type is unknown, then a default of application/octet-stream will be returned.
        Parameters:
        name - The file name to return the mime type for.
        Returns:
        The mime type for the given file name.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        ExternalContext.getMimeType(String)
      • getResource

        public static URL getResource​(String path)
                               throws MalformedURLException
        Returns a URL for an application resource mapped to the specified path, if it exists; otherwise, return null.
        Parameters:
        path - The application resource path to return an input stream for.
        Returns:
        An input stream for an application resource mapped to the specified path.
        Throws:
        NullPointerException - When faces context is unavailable.
        MalformedURLException - When the specified path is not in correct URL form.
        Since:
        1.2
        See Also:
        ExternalContext.getResource(String)
      • getResourceAsStream

        public static InputStream getResourceAsStream​(String path)
        Returns an input stream for an application resource mapped to the specified path, if it exists; otherwise, return null.
        Parameters:
        path - The application resource path to return an input stream for.
        Returns:
        An input stream for an application resource mapped to the specified path.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        ExternalContext.getResourceAsStream(String)
      • getResourcePaths

        public static Set<String> getResourcePaths​(String path)
        Returns a set of available application resource paths matching the specified path.
        Parameters:
        path - The partial application resource path used to return matching resource paths.
        Returns:
        A set of available application resource paths matching the specified path.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        ExternalContext.getResourcePaths(String)
      • getRealPath

        public static String getRealPath​(String webContentPath)
        Returns the absolute disk file system path representation of the given web content path. This thus converts the given path of a web content resource (e.g. /index.xhtml) to an absolute disk file system path (e.g. /path/to/server/work/folder/some.war/index.xhtml) which can then be used in File, FileInputStream, etc.

        Note that this will return null when the WAR is not expanded into the disk file system, but instead into memory. If all you want is just an InputStream of the web content resource, then better use getResourceAsStream(String) instead.

        Also note that it wouldn't make sense to modify or create files in this location, as those changes would get lost anyway when the WAR is redeployed or even when the server is restarted. This is thus absolutely not a good location to store for example uploaded files.

        Parameters:
        webContentPath - The web content path to be converted to an absolute disk file system path.
        Returns:
        The absolute disk file system path representation of the given web content path.
        Throws:
        NullPointerException - When faces context is unavailable.
        Since:
        1.2
      • getRequestAttribute

        public static <T> T getRequestAttribute​(String name)
        Returns the request scope attribute value associated with the given name.
        Type Parameters:
        T - The expected return type.
        Parameters:
        name - The request scope attribute name.
        Returns:
        The request scope attribute value associated with the given name.
        Throws:
        NullPointerException - When faces context is unavailable.
        ClassCastException - When T is of wrong type.
        See Also:
        ExternalContext.getRequestMap()
      • getRequestAttribute

        public static <T> T getRequestAttribute​(String name,
                                                Supplier<T> computeIfAbsent)
        Returns the request scope attribute value associated with the given name, or computes the supplied value if absent.
        Type Parameters:
        T - The expected return type.
        Parameters:
        name - The request scope attribute name.
        computeIfAbsent - The computed request scope attribute value when absent. Useful if it represents a collection, map or bean.
        Returns:
        The request scope attribute value associated with the given name.
        Throws:
        NullPointerException - When faces context is unavailable.
        ClassCastException - When T is of wrong type.
        Since:
        3.0
        See Also:
        ExternalContext.getRequestMap()
      • setRequestAttribute

        public static void setRequestAttribute​(String name,
                                               Object value)
        Sets the request scope attribute value associated with the given name.
        Parameters:
        name - The request scope attribute name.
        value - The request scope attribute value.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        ExternalContext.getRequestMap()
      • removeRequestAttribute

        public static <T> T removeRequestAttribute​(String name)
        Removes the request scope attribute value associated with the given name.
        Type Parameters:
        T - The expected return type.
        Parameters:
        name - The request scope attribute name.
        Returns:
        The request scope attribute value previously associated with the given name, or null if there is no such attribute.
        Throws:
        NullPointerException - When faces context is unavailable.
        ClassCastException - When T is of wrong type.
        Since:
        1.1
        See Also:
        ExternalContext.getRequestMap()
      • getFlash

        public static Flash getFlash()
        Returns the flash scope. Note that Flash implements Map<String, Object>, so you can just treat it like a Map<String, Object>.
        Returns:
        The flash scope.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        ExternalContext.getFlash()
      • getFlashAttribute

        public static <T> T getFlashAttribute​(String name)
        Returns the flash scope attribute value associated with the given name.
        Type Parameters:
        T - The expected return type.
        Parameters:
        name - The flash scope attribute name.
        Returns:
        The flash scope attribute value associated with the given name.
        Throws:
        NullPointerException - When faces context is unavailable.
        ClassCastException - When T is of wrong type.
        See Also:
        ExternalContext.getFlash()
      • getFlashAttribute

        public static <T> T getFlashAttribute​(String name,
                                              Supplier<T> computeIfAbsent)
        Returns the flash scope attribute value associated with the given name, or computes the supplied value if absent.
        Type Parameters:
        T - The expected return type.
        Parameters:
        name - The flash scope attribute name.
        computeIfAbsent - The computed flash scope attribute value when absent. Useful if it represents a collection, map or bean.
        Returns:
        The flash scope attribute value associated with the given name.
        Throws:
        NullPointerException - When faces context is unavailable.
        ClassCastException - When T is of wrong type.
        Since:
        3.0
        See Also:
        ExternalContext.getFlash()
      • setFlashAttribute

        public static void setFlashAttribute​(String name,
                                             Object value)
        Sets the flash scope attribute value associated with the given name.
        Parameters:
        name - The flash scope attribute name.
        value - The flash scope attribute value.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        ExternalContext.getFlash()
      • removeFlashAttribute

        public static <T> T removeFlashAttribute​(String name)
        Removes the flash scope attribute value associated with the given name.
        Type Parameters:
        T - The expected return type.
        Parameters:
        name - The flash scope attribute name.
        Returns:
        The flash scope attribute value previously associated with the given name, or null if there is no such attribute.
        Throws:
        NullPointerException - When faces context is unavailable.
        ClassCastException - When T is of wrong type.
        Since:
        1.1
        See Also:
        ExternalContext.getFlash()
      • getViewAttribute

        public static <T> T getViewAttribute​(String name)
        Returns the view scope attribute value associated with the given name.
        Type Parameters:
        T - The expected return type.
        Parameters:
        name - The view scope attribute name.
        Returns:
        The view scope attribute value associated with the given name.
        Throws:
        NullPointerException - When faces context is unavailable.
        ClassCastException - When T is of wrong type.
        See Also:
        UIViewRoot.getViewMap()
      • getViewAttribute

        public static <T> T getViewAttribute​(String name,
                                             Supplier<T> computeIfAbsent)
        Returns the view scope attribute value associated with the given name, or computes the supplied value if absent.
        Type Parameters:
        T - The expected return type.
        Parameters:
        name - The view scope attribute name.
        computeIfAbsent - The computed view scope attribute value when absent. Useful if it represents a collection, map or bean.
        Returns:
        The view scope attribute value associated with the given name.
        Throws:
        NullPointerException - When faces context is unavailable.
        ClassCastException - When T is of wrong type.
        Since:
        3.0
        See Also:
        UIViewRoot.getViewMap()
      • setViewAttribute

        public static void setViewAttribute​(String name,
                                            Object value)
        Sets the view scope attribute value associated with the given name.
        Parameters:
        name - The view scope attribute name.
        value - The view scope attribute value.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        UIViewRoot.getViewMap()
      • removeViewAttribute

        public static <T> T removeViewAttribute​(String name)
        Removes the view scope attribute value associated with the given name.
        Type Parameters:
        T - The expected return type.
        Parameters:
        name - The view scope attribute name.
        Returns:
        The view scope attribute value previously associated with the given name, or null if there is no such attribute.
        Throws:
        NullPointerException - When faces context is unavailable.
        ClassCastException - When T is of wrong type.
        Since:
        1.1
        See Also:
        UIViewRoot.getViewMap()
      • getSessionAttribute

        public static <T> T getSessionAttribute​(String name)
        Returns the session scope attribute value associated with the given name.
        Type Parameters:
        T - The expected return type.
        Parameters:
        name - The session scope attribute name.
        Returns:
        The session scope attribute value associated with the given name.
        Throws:
        NullPointerException - When faces context is unavailable.
        ClassCastException - When T is of wrong type.
        See Also:
        ExternalContext.getSessionMap()
      • getSessionAttribute

        public static <T> T getSessionAttribute​(String name,
                                                Supplier<T> computeIfAbsent)
        Returns the session scope attribute value associated with the given name, or computes the supplied value if absent.
        Type Parameters:
        T - The expected return type.
        Parameters:
        name - The session scope attribute name.
        computeIfAbsent - The computed session scope attribute value when absent. Useful if it represents a collection, map or bean.
        Returns:
        The session scope attribute value associated with the given name.
        Throws:
        NullPointerException - When faces context is unavailable.
        ClassCastException - When T is of wrong type.
        Since:
        3.0
        See Also:
        ExternalContext.getSessionMap()
      • setSessionAttribute

        public static void setSessionAttribute​(String name,
                                               Object value)
        Sets the session scope attribute value associated with the given name.
        Parameters:
        name - The session scope attribute name.
        value - The session scope attribute value.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        ExternalContext.getSessionMap()
      • removeSessionAttribute

        public static <T> T removeSessionAttribute​(String name)
        Removes the session scope attribute value associated with the given name.
        Type Parameters:
        T - The expected return type.
        Parameters:
        name - The session scope attribute name.
        Returns:
        The session scope attribute value previously associated with the given name, or null if there is no such attribute.
        Throws:
        NullPointerException - When faces context is unavailable.
        ClassCastException - When T is of wrong type.
        Since:
        1.1
        See Also:
        ExternalContext.getSessionMap()
      • getApplicationAttribute

        public static <T> T getApplicationAttribute​(String name)
        Returns the application scope attribute value associated with the given name.
        Type Parameters:
        T - The expected return type.
        Parameters:
        name - The application scope attribute name.
        Returns:
        The application scope attribute value associated with the given name.
        Throws:
        NullPointerException - When faces context is unavailable.
        ClassCastException - When T is of wrong type.
        See Also:
        ExternalContext.getApplicationMap()
      • getApplicationAttribute

        public static <T> T getApplicationAttribute​(String name,
                                                    Supplier<T> computeIfAbsent)
        Returns the application scope attribute value associated with the given name, or computes the supplied value if absent.
        Type Parameters:
        T - The expected return type.
        Parameters:
        name - The application scope attribute name.
        computeIfAbsent - The computed application scope attribute value when absent. Useful if it represents a collection, map or bean.
        Returns:
        The application scope attribute value associated with the given name.
        Throws:
        NullPointerException - When faces context is unavailable.
        ClassCastException - When T is of wrong type.
        Since:
        3.0
        See Also:
        ExternalContext.getApplicationMap()
      • setApplicationAttribute

        public static void setApplicationAttribute​(String name,
                                                   Object value)
        Sets the application scope attribute value associated with the given name.
        Parameters:
        name - The application scope attribute name.
        value - The application scope attribute value.
        Throws:
        NullPointerException - When faces context is unavailable.
        See Also:
        ExternalContext.getApplicationMap()
      • removeApplicationAttribute

        public static <T> T removeApplicationAttribute​(String name)
        Removes the application scope attribute value associated with the given name.
        Type Parameters:
        T - The expected return type.
        Parameters:
        name - The application scope attribute name.
        Returns:
        The application scope attribute value previously associated with the given name, or null if there is no such attribute.
        Throws:
        NullPointerException - When faces context is unavailable.
        ClassCastException - When T is of wrong type.
        Since:
        1.1
        See Also:
        ExternalContext.getApplicationMap()
      • sendFile

        public static void sendFile​(File file,
                                    boolean attachment)
                             throws IOException
        Send the given file to the response. The file name will be derived from File.getName(). The content type will be determined based on file name. The content length will be set to the length of the file. The FacesContext.responseComplete() will implicitly be called after successful streaming.
        Parameters:
        file - The file to be sent to the response.
        attachment - Whether the file should be provided as attachment, or just inline.
        Throws:
        NullPointerException - When faces context is unavailable.
        IOException - When given file cannot be read.
        UncheckedIOException - When HTTP response is not available anymore.
      • sendFile

        public static void sendFile​(File file,
                                    String filename,
                                    boolean attachment)
                             throws IOException
        Send the given file to the response. The content type will be determined based on file name. The content length will be set to the length of the file. The FacesContext.responseComplete() will implicitly be called after successful streaming.
        Parameters:
        file - The file to be sent to the response.
        filename - The file name which should appear in content disposition header.
        attachment - Whether the file should be provided as attachment, or just inline.
        Throws:
        NullPointerException - When faces context is unavailable.
        IOException - When given file cannot be read.
        UncheckedIOException - When HTTP response is not available anymore.
        Since:
        3.9
      • sendFile

        public static void sendFile​(Path path,
                                    boolean attachment)
                             throws IOException
        Send the given path as a file to the response. The file will be derived from Path.toFile() and then the file name will be derived from File.getName(). The content type will be determined based on file name. The content length will be set to the length of the file. The FacesContext.responseComplete() will implicitly be called after successful streaming.
        Parameters:
        path - The path to be sent as a file to the response.
        attachment - Whether the file should be provided as attachment, or just inline.
        Throws:
        NullPointerException - When faces context is unavailable.
        IOException - When given file cannot be read.
        UncheckedIOException - When HTTP response is not available anymore.
        Since:
        3.9
      • sendFile

        public static void sendFile​(Path path,
                                    String filename,
                                    boolean attachment)
                             throws IOException
        Send the given path as a file to the response. The file will be derived from Path.toFile(). The content type will be determined based on file name. The content length will be set to the length of the file. The FacesContext.responseComplete() will implicitly be called after successful streaming.
        Parameters:
        path - The path to be sent as a file to the response.
        filename - The file name which should appear in content disposition header.
        attachment - Whether the file should be provided as attachment, or just inline.
        Throws:
        NullPointerException - When faces context is unavailable.
        IOException - When given file cannot be read.
        UncheckedIOException - When HTTP response is not available anymore.
        Since:
        3.9
      • sendFile

        public static void sendFile​(byte[] content,
                                    String filename,
                                    boolean attachment)
        Send the given byte array as a file to the response. The content type will be determined based on file name. The content length will be set to the length of the byte array. The FacesContext.responseComplete() will implicitly be called after successful streaming.
        Parameters:
        content - The file content as byte array.
        filename - The file name which should appear in content disposition header.
        attachment - Whether the file should be provided as attachment, or just inline.
        Throws:
        NullPointerException - When faces context is unavailable.
        UncheckedIOException - When HTTP response is not available anymore.
      • sendFile

        public static void sendFile​(InputStream content,
                                    String filename,
                                    boolean attachment)
        Send the given input stream as a file to the response. The content type will be determined based on file name. The content length may not be set because that's not predictable based on input stream. The client may receive a download of an unknown length and thus the download progress may be unknown to the client. Only if the input stream is smaller than the default buffer size, then the content length will be set. The InputStream.close() will implicitly be called after streaming, regardless of whether an exception is been thrown or not. The FacesContext.responseComplete() will implicitly be called after successful streaming.
        Parameters:
        content - The file content as input stream.
        filename - The file name which should appear in content disposition header.
        attachment - Whether the file should be provided as attachment, or just inline.
        Throws:
        NullPointerException - When faces context is unavailable.
        UncheckedIOException - When HTTP response is not available anymore.
      • sendFile

        public static void sendFile​(String filename,
                                    boolean attachment,
                                    Callback.Output outputCallback)
        Send a file to the response whose content is provided via given output stream callback. The content type will be determined based on file name. The content length will not be set because that would require buffering the entire file in memory or temp disk. The client may receive a download of an unknown length and thus the download progress may be unknown to the client. If this is undesirable, write to a temp file instead and then use sendFile(File, boolean). The FacesContext.responseComplete() will implicitly be called after successful streaming.
        Parameters:
        filename - The file name which should appear in content disposition header.
        attachment - Whether the file should be provided as attachment, or just inline.
        outputCallback - The output stream callback to write the file content to.
        Throws:
        NullPointerException - When faces context is unavailable.
        UncheckedIOException - When HTTP response is not available anymore.
        Since:
        2.3