Class ComponentUtils


  • public final class ComponentUtils
    extends Object
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static jakarta.faces.component.UIComponent createComponent​(jakarta.faces.context.FacesContext facesContext, String componentType, RendererTypes rendererType, String clientId)  
      static void evaluateAutoFor​(jakarta.faces.component.UIComponent component, Class<? extends jakarta.faces.component.UIComponent> clazz)
      Looks for the attribute "for" of the component.
      static String evaluateClientId​(jakarta.faces.context.FacesContext context, jakarta.faces.component.UIComponent component, String componentId)
      Resolves the real clientId.
      static String evaluateClientIds​(jakarta.faces.context.FacesContext context, jakarta.faces.component.UIComponent component, String[] componentIds)
      Resolves the real clientIds.
      static <T> T findAncestor​(jakarta.faces.component.UIComponent component, Class<T> type)  
      static <T extends jakarta.faces.component.UIComponent>
      T
      findChild​(jakarta.faces.component.UIComponent component, Class<T> type)
      Searches the children beneath the component and return the first component matching the type.
      static String findClientIdFor​(jakarta.faces.component.UIComponent component, jakarta.faces.context.FacesContext facesContext)
      Looks for the attribute "for" in the component.
      static jakarta.faces.component.UIComponent findComponent​(jakarta.faces.component.UIComponent from, String relativeId)
      The search depends on the number of prefixed colons in the relativeId:
      static jakarta.faces.component.UIComponent findComponent​(jakarta.faces.context.FacesContext facesContext, jakarta.faces.component.UIComponent from, String relativeId)
      The search depends on the number of prefixed colons in the relativeId:
      static <T extends jakarta.faces.component.UIComponent>
      T
      findDescendant​(jakarta.faces.component.UIComponent component, Class<T> type)
      Searches the component tree beneath the component and return the first component matching the type.
      static <T extends jakarta.faces.component.UIComponent>
      List<T>
      findDescendantList​(jakarta.faces.component.UIComponent component, Class<T> type)
      Searches the component tree beneath the component and return all component matching the type.
      static <T extends jakarta.faces.component.UIComponent>
      T
      findFacetDescendant​(jakarta.faces.component.UIComponent component, Facets facet, Class<T> type)
      Searches the component tree beneath the component and return the first component matching the type.
      static jakarta.faces.component.UIComponent findFor​(jakarta.faces.component.UIComponent component)  
      static AbstractUIFormBase findForm​(jakarta.faces.component.UIComponent component)  
      static List<jakarta.faces.component.UIComponent> findLayoutChildren​(jakarta.faces.component.UIComponent container)  
      static AbstractUIPage findPage​(jakarta.faces.component.UIComponent component)  
      static AbstractUIPage findPage​(jakarta.faces.context.FacesContext facesContext)  
      static AbstractUIPage findPage​(jakarta.faces.context.FacesContext context, jakarta.faces.component.UIComponent component)  
      static Object findParameter​(jakarta.faces.component.UIComponent component, String name)  
      static List<AbstractUIForm> findSubForms​(jakarta.faces.component.UIComponent component)
      Find all sub forms of a component, and collects it.
      static jakarta.faces.component.UIViewRoot findViewRoot​(jakarta.faces.view.facelets.FaceletContext faceletContext, jakarta.faces.component.UIComponent component)
      Tries to walk up the parents to find the UIViewRoot, if not found, then go to FaceletContext's FacesContext for the view root.
      static Object getAttribute​(jakarta.faces.component.UIComponent component, Attributes name)  
      static boolean getBooleanAttribute​(jakarta.faces.component.UIComponent component, Attributes name)  
      static boolean getBooleanAttribute​(jakarta.faces.component.UIComponent component, Attributes name, boolean defaultValue)  
      static Character getCharacterAttribute​(jakarta.faces.component.UIComponent component, Attributes name)  
      static String getConfirmation​(jakarta.faces.component.UIComponent component)
      returns the "confirmation" attribute or the value of the "confirmation" facet of a component.
      static Object getConvertedValue​(jakarta.faces.context.FacesContext facesContext, jakarta.faces.component.UIComponent component, String stringValue)  
      static jakarta.faces.convert.Converter getConverter​(jakarta.faces.context.FacesContext facesContext, jakarta.faces.component.UIComponent component, Object value)
      Deprecated.
      since 5.0.0.
      static Object getDataAttribute​(jakarta.faces.component.UIComponent component, String name)  
      static Map<Object,​Object> getDataAttributes​(jakarta.faces.component.UIComponent component)  
      static String getFacesMessageAsString​(jakarta.faces.context.FacesContext facesContext, jakarta.faces.component.UIComponent component)  
      static jakarta.faces.component.UIComponent getFacet​(jakarta.faces.component.UIComponent component, Facets facet)  
      static String getFormattedValue​(jakarta.faces.context.FacesContext facesContext, jakarta.faces.component.UIComponent component, Object currentValue)
      Deprecated.
      since 5.0.0.
      static int getIntAttribute​(jakarta.faces.component.UIComponent component, Attributes name)  
      static int getIntAttribute​(jakarta.faces.component.UIComponent component, Attributes name, int defaultValue)  
      static jakarta.faces.application.FacesMessage.Severity getMaximumSeverity​(jakarta.faces.component.UIComponent component)  
      static jakarta.faces.application.FacesMessage.Severity getMaximumSeverity​(List<jakarta.faces.application.FacesMessage> messages)  
      static jakarta.faces.application.FacesMessage.Severity getMaximumSeverityOfChildrenMessages​(jakarta.faces.context.FacesContext facesContext, jakarta.faces.component.NamingContainer container)  
      static AbstractUIReload getReloadFacet​(jakarta.faces.component.UIComponent component)  
      static RendererBase getRenderer​(jakarta.faces.context.FacesContext facesContext, jakarta.faces.component.UIComponent component)  
      static RendererBase getRenderer​(jakarta.faces.context.FacesContext facesContext, String family, String rendererType)  
      static String getStringAttribute​(jakarta.faces.component.UIComponent component, Attributes name)  
      static String getStringAttribute​(jakarta.faces.component.UIComponent component, Attributes name, String defaultValue)  
      static boolean hasErrorMessages​(jakarta.faces.context.FacesContext context)
      Deprecated.
      since 3.0.1
      static boolean isError​(jakarta.faces.component.UIComponent component)
      Deprecated.
      since 5.0.0
      static boolean isError​(jakarta.faces.component.UIInput uiInput)
      Deprecated.
      since 5.0.0
      static boolean isFacetOf​(jakarta.faces.component.UIComponent component, jakarta.faces.component.UIComponent parent)
      Deprecated.
      since 5.0.0
      static boolean isInActiveForm​(jakarta.faces.component.UIComponent component)
      Deprecated.
      since 4.0.0
      static boolean isInPopup​(jakarta.faces.component.UIComponent component)
      Deprecated.
      since 3.0.1
      static boolean isOutputOnly​(jakarta.faces.component.UIComponent component)
      Deprecated.
      since 5.0.0
      static Markup markupOfSeverity​(jakarta.faces.application.FacesMessage.Severity maximumSeverity)  
      static void putDataAttribute​(jakarta.faces.component.UIComponent component, Object name, Object value)
      Adding a data attribute to the component.
      static void putDataAttributeWithPrefix​(jakarta.faces.component.UIComponent component, DataAttributes name, Object value)
      Adding a data attribute to the component.
      static void removeAttribute​(jakarta.faces.component.UIComponent component, Attributes name)  
      static void removeFacet​(jakarta.faces.component.UIComponent component, Facets facet)  
      static void resetPage​(jakarta.faces.context.FacesContext context)
      Deprecated.
      since 3.0.1
      static void setAttribute​(jakarta.faces.component.UIComponent component, Attributes name, Object value)  
      static void setFacet​(jakarta.faces.component.UIComponent component, Facets facet, jakarta.faces.component.UIComponent child)  
      static String[] splitList​(String renderers)  
    • Field Detail

      • ACTION_ARGS

        public static final Class[] ACTION_ARGS
      • ACTION_LISTENER_ARGS

        public static final Class[] ACTION_LISTENER_ARGS
      • VALUE_CHANGE_LISTENER_ARGS

        public static final Class[] VALUE_CHANGE_LISTENER_ARGS
      • VALIDATOR_ARGS

        public static final Class[] VALIDATOR_ARGS
      • DATA_ATTRIBUTES_KEY

        public static final String DATA_ATTRIBUTES_KEY
        Name of the map for data attributes in components. New in JSF 2.2.
        Since:
        2.0.0
        See Also:
        Constant Field Values
    • Method Detail

      • hasErrorMessages

        @Deprecated
        public static boolean hasErrorMessages​(jakarta.faces.context.FacesContext context)
        Deprecated.
        since 3.0.1
      • getFacesMessageAsString

        public static String getFacesMessageAsString​(jakarta.faces.context.FacesContext facesContext,
                                                     jakarta.faces.component.UIComponent component)
      • isInPopup

        @Deprecated
        public static boolean isInPopup​(jakarta.faces.component.UIComponent component)
        Deprecated.
        since 3.0.1
      • resetPage

        @Deprecated
        public static void resetPage​(jakarta.faces.context.FacesContext context)
        Deprecated.
        since 3.0.1
      • findViewRoot

        public static jakarta.faces.component.UIViewRoot findViewRoot​(jakarta.faces.view.facelets.FaceletContext faceletContext,
                                                                      jakarta.faces.component.UIComponent component)
        Tries to walk up the parents to find the UIViewRoot, if not found, then go to FaceletContext's FacesContext for the view root.
      • findPage

        public static AbstractUIPage findPage​(jakarta.faces.context.FacesContext context,
                                              jakarta.faces.component.UIComponent component)
      • findPage

        public static AbstractUIPage findPage​(jakarta.faces.component.UIComponent component)
      • findPage

        public static AbstractUIPage findPage​(jakarta.faces.context.FacesContext facesContext)
      • findForm

        public static AbstractUIFormBase findForm​(jakarta.faces.component.UIComponent component)
      • findAncestor

        public static <T> T findAncestor​(jakarta.faces.component.UIComponent component,
                                         Class<T> type)
      • findSubForms

        public static List<AbstractUIForm> findSubForms​(jakarta.faces.component.UIComponent component)
        Find all sub forms of a component, and collects it. It does not find sub forms of sub forms.
      • findDescendant

        public static <T extends jakarta.faces.component.UIComponent> T findDescendant​(jakarta.faces.component.UIComponent component,
                                                                                       Class<T> type)
        Searches the component tree beneath the component and return the first component matching the type.
      • findFacetDescendant

        public static <T extends jakarta.faces.component.UIComponent> T findFacetDescendant​(jakarta.faces.component.UIComponent component,
                                                                                            Facets facet,
                                                                                            Class<T> type)
        Searches the component tree beneath the component and return the first component matching the type.
      • findChild

        public static <T extends jakarta.faces.component.UIComponent> T findChild​(jakarta.faces.component.UIComponent component,
                                                                                  Class<T> type)
        Searches the children beneath the component and return the first component matching the type.
      • findDescendantList

        public static <T extends jakarta.faces.component.UIComponent> List<T> findDescendantList​(jakarta.faces.component.UIComponent component,
                                                                                                 Class<T> type)
        Searches the component tree beneath the component and return all component matching the type.
      • findClientIdFor

        public static String findClientIdFor​(jakarta.faces.component.UIComponent component,
                                             jakarta.faces.context.FacesContext facesContext)
        Looks for the attribute "for" in the component. If there is any search for the component which is referenced by the "for" attribute, and return their clientId. If there is no "for" attribute, return the "clientId" of the parent (if it has a parent). This is useful for labels.
      • findFor

        public static jakarta.faces.component.UIComponent findFor​(jakarta.faces.component.UIComponent component)
      • evaluateAutoFor

        public static void evaluateAutoFor​(jakarta.faces.component.UIComponent component,
                                           Class<? extends jakarta.faces.component.UIComponent> clazz)
        Looks for the attribute "for" of the component. In case that the value is equals to "@auto" the children of the parent will be checked if they are of the type of the parameter clazz. The "id" of the first one will be used to reset the "for" attribute of the component.
      • isInActiveForm

        @Deprecated
        public static boolean isInActiveForm​(jakarta.faces.component.UIComponent component)
        Deprecated.
        since 4.0.0
      • getMaximumSeverity

        public static jakarta.faces.application.FacesMessage.Severity getMaximumSeverity​(jakarta.faces.component.UIComponent component)
      • getMaximumSeverity

        public static jakarta.faces.application.FacesMessage.Severity getMaximumSeverity​(List<jakarta.faces.application.FacesMessage> messages)
      • isError

        @Deprecated
        public static boolean isError​(jakarta.faces.component.UIInput uiInput)
        Deprecated.
        since 5.0.0
      • isError

        @Deprecated
        public static boolean isError​(jakarta.faces.component.UIComponent component)
        Deprecated.
        since 5.0.0
      • isOutputOnly

        @Deprecated
        public static boolean isOutputOnly​(jakarta.faces.component.UIComponent component)
        Deprecated.
        since 5.0.0
      • getAttribute

        public static Object getAttribute​(jakarta.faces.component.UIComponent component,
                                          Attributes name)
      • getBooleanAttribute

        public static boolean getBooleanAttribute​(jakarta.faces.component.UIComponent component,
                                                  Attributes name)
      • getBooleanAttribute

        public static boolean getBooleanAttribute​(jakarta.faces.component.UIComponent component,
                                                  Attributes name,
                                                  boolean defaultValue)
      • getStringAttribute

        public static String getStringAttribute​(jakarta.faces.component.UIComponent component,
                                                Attributes name)
      • getStringAttribute

        public static String getStringAttribute​(jakarta.faces.component.UIComponent component,
                                                Attributes name,
                                                String defaultValue)
      • getIntAttribute

        public static int getIntAttribute​(jakarta.faces.component.UIComponent component,
                                          Attributes name)
      • getIntAttribute

        public static int getIntAttribute​(jakarta.faces.component.UIComponent component,
                                          Attributes name,
                                          int defaultValue)
      • getCharacterAttribute

        public static Character getCharacterAttribute​(jakarta.faces.component.UIComponent component,
                                                      Attributes name)
      • setAttribute

        public static void setAttribute​(jakarta.faces.component.UIComponent component,
                                        Attributes name,
                                        Object value)
      • removeAttribute

        public static void removeAttribute​(jakarta.faces.component.UIComponent component,
                                           Attributes name)
      • getFacet

        public static jakarta.faces.component.UIComponent getFacet​(jakarta.faces.component.UIComponent component,
                                                                   Facets facet)
      • setFacet

        public static void setFacet​(jakarta.faces.component.UIComponent component,
                                    Facets facet,
                                    jakarta.faces.component.UIComponent child)
      • removeFacet

        public static void removeFacet​(jakarta.faces.component.UIComponent component,
                                       Facets facet)
      • getReloadFacet

        public static AbstractUIReload getReloadFacet​(jakarta.faces.component.UIComponent component)
      • isFacetOf

        @Deprecated
        public static boolean isFacetOf​(jakarta.faces.component.UIComponent component,
                                        jakarta.faces.component.UIComponent parent)
        Deprecated.
        since 5.0.0
      • getRenderer

        public static RendererBase getRenderer​(jakarta.faces.context.FacesContext facesContext,
                                               jakarta.faces.component.UIComponent component)
      • getRenderer

        public static RendererBase getRenderer​(jakarta.faces.context.FacesContext facesContext,
                                               String family,
                                               String rendererType)
      • findParameter

        public static Object findParameter​(jakarta.faces.component.UIComponent component,
                                           String name)
      • findComponent

        public static jakarta.faces.component.UIComponent findComponent​(jakarta.faces.component.UIComponent from,
                                                                        String relativeId)

        The search depends on the number of prefixed colons in the relativeId:

        number of prefixed colons == 0
        fully relative
        number of prefixed colons == 1
        absolute (still normal findComponent syntax)
        number of prefixed colons == 2
        search in the current naming container (same as 0 colons)
        number of prefixed colons == 3
        search in the parent naming container of the current naming container
        number of prefixed colons > 3
        go to the next parent naming container for each additional colon

        If a literal is specified: to use more than one identifier the identifiers must be space delimited.

      • findComponent

        public static jakarta.faces.component.UIComponent findComponent​(jakarta.faces.context.FacesContext facesContext,
                                                                        jakarta.faces.component.UIComponent from,
                                                                        String relativeId)

        The search depends on the number of prefixed colons in the relativeId:

        number of prefixed colons == 0
        fully relative
        number of prefixed colons == 1
        absolute (still normal findComponent syntax)
        number of prefixed colons == 2
        search in the current naming container (same as 0 colons)
        number of prefixed colons == 3
        search in the parent naming container of the current naming container
        number of prefixed colons > 3
        go to the next parent naming container for each additional colon

        If a literal is specified: to use more than one identifier the identifiers must be space delimited.

      • evaluateClientIds

        public static String evaluateClientIds​(jakarta.faces.context.FacesContext context,
                                               jakarta.faces.component.UIComponent component,
                                               String[] componentIds)
        Resolves the real clientIds.
      • evaluateClientId

        public static String evaluateClientId​(jakarta.faces.context.FacesContext context,
                                              jakarta.faces.component.UIComponent component,
                                              String componentId)
        Resolves the real clientId.
      • splitList

        public static String[] splitList​(String renderers)
      • getConvertedValue

        public static Object getConvertedValue​(jakarta.faces.context.FacesContext facesContext,
                                               jakarta.faces.component.UIComponent component,
                                               String stringValue)
      • markupOfSeverity

        public static Markup markupOfSeverity​(jakarta.faces.application.FacesMessage.Severity maximumSeverity)
      • getMaximumSeverityOfChildrenMessages

        public static jakarta.faces.application.FacesMessage.Severity getMaximumSeverityOfChildrenMessages​(jakarta.faces.context.FacesContext facesContext,
                                                                                                           jakarta.faces.component.NamingContainer container)
      • putDataAttributeWithPrefix

        public static void putDataAttributeWithPrefix​(jakarta.faces.component.UIComponent component,
                                                      DataAttributes name,
                                                      Object value)
        Adding a data attribute to the component. The name must start with "data-", e. g. "data-tobago-foo" or "data-bar"
      • putDataAttribute

        public static void putDataAttribute​(jakarta.faces.component.UIComponent component,
                                            Object name,
                                            Object value)
        Adding a data attribute to the component. The name should not start with "data-", e. g. "tobago-foo" or "bar"
      • getDataAttributes

        public static Map<Object,​Object> getDataAttributes​(jakarta.faces.component.UIComponent component)
      • getDataAttribute

        public static Object getDataAttribute​(jakarta.faces.component.UIComponent component,
                                              String name)
      • createComponent

        public static jakarta.faces.component.UIComponent createComponent​(jakarta.faces.context.FacesContext facesContext,
                                                                          String componentType,
                                                                          RendererTypes rendererType,
                                                                          String clientId)
      • findLayoutChildren

        public static List<jakarta.faces.component.UIComponent> findLayoutChildren​(jakarta.faces.component.UIComponent container)
      • getConfirmation

        public static String getConfirmation​(jakarta.faces.component.UIComponent component)
        returns the "confirmation" attribute or the value of the "confirmation" facet of a component.
        Since:
        Tobago 4.4.0