Class FacesHelper


  • public class FacesHelper
    extends Object
    • Method Detail

      • createDynamicResourceUrl

        public static String createDynamicResourceUrl​(javax.faces.context.FacesContext context,
                                                      String expression,
                                                      Map<String,​String> params,
                                                      boolean cache)
        Parameters:
        context - Current faces context.
        expression - Expression to invoke when the resource needs to be fetched, e.g. a bean method. It must return a StreamedContent.
        params - URL parameters to include in the resource URL.
        cache - Whether the resource can be cached.
        Returns:
        The URL for a dynamic resource that retrieves data from the given expression (e.g. a bean method).
      • getBeanCreateIfMissing

        public static <T> T getBeanCreateIfMissing​(Class<T> beanClass,
                                                   Annotation... qualifiers)
        Returns the JSF bean (request scoped, view scoped, session scoped, conversation scoped, or application scoped) of the given class. When the bean was not created yet, creates the bean.
        Type Parameters:
        T - Type of the bean to lookup.
        Parameters:
        beanClass - Class of the bean to lookup.
        qualifiers - Optional qualifiers for the bean.
        Returns:
        The bean instance of the given class.
      • getBeanName

        public static String getBeanName​(Class<?> beanClass,
                                         Annotation... qualifiers)
        Parameters:
        beanClass - Class of the bean to lookup.
        qualifiers - Optional qualifiers for the bean.
        Returns:
        The name of the JSF bean (request scoped, view scoped, session scoped, conversation scoped, or application scoped).
      • getBeanNullIfMissing

        @Nullable
        public static <T> T getBeanNullIfMissing​(Class<T> beanClass,
                                                 Annotation... qualifiers)
        Checks if an instance of the JSF bean (request scoped, view scoped, session scoped, conversation scoped, or application scoped) exists, and returns the bean if it does. When the bean was not created yet, returns null.
        Type Parameters:
        T - Type of the bean to lookup.
        Parameters:
        beanClass - Class of the bean to lookup.
        qualifiers - Optional qualifiers for the bean.
        Returns:
        The bean instance if the bean was created already, or null otherwise.
      • maxSeverity

        public static javax.faces.application.FacesMessage.Severity maxSeverity​(javax.faces.application.FacesMessage.Severity lhs,
                                                                                javax.faces.application.FacesMessage.Severity rhs)
        Parameters:
        lhs - First severity to process.
        rhs - Second severity to process.
        Returns:
        The severity with the higher level. The order is fatal, error, , , from highest to lowest.
      • showDialogByWidgetVar

        public static void showDialogByWidgetVar​(String widgetVar)
      • hideDialogByWidgetVar

        public static void hideDialogByWidgetVar​(String widgetVar)
      • getCurrentForms

        public static Set<javax.faces.component.UIForm> getCurrentForms​(javax.faces.context.FacesContext context)
        Similar to Components.getCurrentForm(), but finds all forms. Strictly speaking, JSF only allows one form to be executed during postback. For non-AJAX requests, only one form is possible. But for AJAX requests, PrimeFaces supports components from different forms to be executed (processed).

        Returns the currently submitted UI form components, or empty set if there is none, which may happen when the current request is not a postback request at all, or when the view has been changed by for example a successful navigation. If the latter is the case, you'd better invoke this method before navigation.

        Parameters:
        context - Current faces context.
        Returns:
        The currently submitted UI form components.