Class FacesHelper


  • public class FacesHelper
    extends Object
    • Method Detail

      • addJavaScriptResourceOnce

        public static void addJavaScriptResourceOnce​(javax.faces.context.FacesContext context,
                                                     String id,
                                                     String name,
                                                     String library)
        Dynamically adds a JavaScript resource to the current page. Should be called before the actual rendering phase. The resource is only added once during a view scope.
        Parameters:
        context - Current faces context to use.
        id - Optional ID of the resource, when it gets rendered as a script tag.
        name - File name of the resource.
        library - Library of the resource. May be null or empty when no library should be used.
      • addJavaScriptResourceOnce

        public static void addJavaScriptResourceOnce​(javax.faces.context.FacesContext context,
                                                     String id,
                                                     String name,
                                                     String library,
                                                     String onLoaded)
        Dynamically adds a JavaScript resource to the current page. Should be called before the actual rendering phase. The resource is only added once during a view scope.
        Parameters:
        context - Current faces context to use.
        id - Optional ID of the resource, when it gets rendered as a script tag.
        name - File name of the resource.
        library - Library of the resource. May be null or empty when no library should be used.
        onLoaded - JavaScript to execute when the script was loaded.
      • addJavaScriptResourceOnce

        public static void addJavaScriptResourceOnce​(javax.faces.context.FacesContext context,
                                                     String id,
                                                     String name,
                                                     String library,
                                                     String onLoaded,
                                                     String devPath)
        Dynamically adds a JavaScript resource to the current page. Should be called before the actual rendering phase. The resource is only added once during a view scope.
        Parameters:
        context - Current faces context to use.
        id - Optional ID of the resource, when it gets rendered as a script tag.
        name - File name of the resource.
        library - Library of the resource. May be null or empty when no library should be used.
        devPath - Optional dev path for loading the resource from disk during development.
        onLoaded - JavaScript to execute when the script was loaded.
      • addJavaScriptResourceInline

        public static void addJavaScriptResourceInline​(javax.faces.context.FacesContext context,
                                                       String code,
                                                       String target)
        Adds a JavaScript code snippet as a <script></script> tag to the page. Works only during the initial render.
        Parameters:
        context - Current faces context to use.
        code - JavaScript code to add.
        target - The name of the facet for which the UIComponent will be added, e.g. head.
      • 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

        @Deprecated
        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

        @Deprecated
        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
        @Deprecated
        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.
      • 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.
      • getViewScopedStateChangeTrackers

        public static Set<IStateHolder> getViewScopedStateChangeTrackers​(javax.faces.context.FacesContext facesContext)
        Returns all beans that implement IStateHolder from the current view map.
        Parameters:
        facesContext - Current faces context.
        Returns:
        All beans that implement IStateHolder from the current view map.
      • getLocaleOrDefault

        public static Locale getLocaleOrDefault()
        Returns:
        The locale from the current Faces context, or the default locale when there is no active Faces context or it does not have a locale set.
      • hideDialogByWidgetVar

        public static void hideDialogByWidgetVar​(String widgetVar)
      • 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, warn, info, from highest to lowest.
      • showDialogByWidgetVar

        public static void showDialogByWidgetVar​(String widgetVar)